如何生成保存在单个 .tex 文件中的当前月份的正在进行的笔记本的 PDF

如何生成保存在单个 .tex 文件中的当前月份的正在进行的笔记本的 PDF

我正在使用这个实验室手册模板:

http://www.ctan.org/tex-archive/macros/latex/contrib/labbook

虽然最初是为实验室工作而设计的,但我用它来记录我在工作(技术工作)中所做的事情。我目前已将其设置为每个月都有一个单独的文档。以下示例仅取自模板示例文档中的几天,但包含我的文档的所有重要结构。

\documentclass[idxtotoc,hyperref,openany]{labbook} 
\usepackage[ 
   backref=page,
   pdfpagelabels=true,
   plainpages=false,
   colorlinks=true,
   bookmarks=true,
   pdfview=FitB]{hyperref} % Required for the hyperlinks within the PDF

\usepackage{booktabs} % Required for the top and bottom rules in the table
\usepackage{float} % Required for specifying the exact location of a figure or table
\usepackage{graphicx} % Required for including images
\usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}} % Command to make the lines in the title page
\setlength\parindent{0pt} % Removes all indentation from paragraphs
\begin{document}

\frontmatter % Use Roman numerals for page numbers
\title{
\begin{center}
\HRule \\[0.4cm]
{\Huge \bfseries Laboratory Journal \\[0.5cm] \Large Master of Science}\\[0.4cm] % Degree
\HRule \\[1.5cm]
\end{center}
}
\author{\Huge John Smith \\ \\ \LARGE [email protected] \\[2cm]} % Your name and email address
\date{Beginning 6 February 2012} % Beginning date
\maketitle
\tableofcontents
\mainmatter % Use Arabic numerals for page numbers

\labday{Friday, 25 November 2011}
\experiment{Experiment 1}
\lipsum[1]
\experiment{Example with a figure} % Multiple experiments can be included in a single day, this allows you to segment what was done each day into separate categories

\begin{figure}[H] % Example of including images
\begin{center}
\includegraphics[width=0.5\linewidth]{example_figure}
\end{center}
\caption{Example figure.}
\label{fig:example_figure}
\end{figure}
\experiment{Just text notes}
\lipsum[3-5]

\labday{Friday, 26 March 2010}
\experiment{Table Example}
\begin{table}[H]
\begin{tabular}{l l l}
\toprule
\textbf{Groups} & \textbf{Treatment X} & \textbf{Treatment Y} \\
\toprule
1 & 0.2 & 0.8\\
2 & 0.17 & 0.7\\
3 & 0.24 & 0.75\\
4 & 0.68 & 0.3\\
\bottomrule
\end{tabular}
\caption{The effects of treatments X and Y on the four groups studied.}
\label{tab:treatments_xy}
\end{table}

Table \ref{tab:treatments_xy} shows that groups 1-3 reacted similarly to the two treatments but group 4 showed a reversed reaction.

\end{document}

我更愿意持续地(从现在开始直到永远)保留这些笔记的 .tex 文档,或者每年保留一次以保持可搜索性,并在每个月末生成当月的 pdf。

我还非常希望避免为此创建每月模板文档并将相关部分复制到新的 .tex 文件中。

我使用的是 MiKTeX 2.9 和 TeXworks 0.4.6 前端。我使用 pdfLaTeX 将其转换为 pdf

有没有办法告诉解释器只执行文档的一部分并忽略其余部分?

答案1

更新:新版本使用日期编号。如果我做得正确的话,这次它甚至可能像广告中说的那样有效……


这是使用该包的方法环境定义新环境labmonth。用户界面的工作方式如下:

  • 实验室笔记是在环境范围内写的labmonth,它接受一个强制参数,该参数应以形式指定年份和月份YYYY-MM

  • \onlylabmonth{YYYY-MM}labmonth将导致仅排版指定环境的内容;

  • \onlylabyear{YYYY}labmonth将导致仅排版指定年份的内容;

  • \labmonthstart{YYYY-MM}阻止早期的labmonths 被排版;

  • \labmonthend{YYYY-MM}防止后面的labmonths 被排版。

这个想法是\labmonthstart{YYYY-MM}设置第一个所需月份并\labmonthend{YYYY-MM}设置最后一个所需月份。\onlylabmonth{YYYY-MM}\onlylabyear{YYYY-MM}是方便的包装器,用于需要排版恰好一个月或恰好一年的笔记的情况。

需要添加到序言中的代码如下:

\usepackage{environ,datenumber}
\makeatletter
\newcounter{tuffver@labmonth@startdate}
\newcounter{tuffver@labmonth@enddate}
\def\tuffver@labmonth@year#1-#2\null{#1}
\def\tuffver@labmonth@month#1-#2\null{#2}
\newcommand*\labmonthstart[1]{%
  \xdef\tuffver@labmonth@start@year{\expandafter\tuffver@labmonth@year#1\null}%
  \xdef\tuffver@labmonth@start@month{\expandafter\tuffver@labmonth@month#1\null}%
  \setmydatenumber{tuffver@labmonth@startdate}{\tuffver@labmonth@start@year}{\tuffver@labmonth@start@month}{01}%
}
\newcommand*\labmonthend[1]{%
  \xdef\tuffver@labmonth@end@year{\expandafter\tuffver@labmonth@year#1\null}%
  \xdef\tuffver@labmonth@end@month{\expandafter\tuffver@labmonth@month#1\null}%
  \setmydatenumber{tuffver@labmonth@enddate}{\tuffver@labmonth@end@year}{\tuffver@labmonth@end@month}{01}%
}
\newcommand*\onlylabmonth[1]{%
  \labmonthstart{#1}%
  \labmonthend{#1}%
}
\newcommand*\onlylabyear[1]{%
  \labmonthstart{#1-01}%
  \labmonthend{#1-12}%
}
\labmonthstart{1800-01}
\labmonthend{2100-12}
\environbodyname\tuffver@labmonth@body
\NewEnviron{labmonth}[1]
{%
  \edef\tempa{\expandafter\tuffver@labmonth@year#1\null}%
  \edef\tempb{\expandafter\tuffver@labmonth@month#1\null}%
  \setdatenumber{\tempa}{\tempb}{01}%
  \ifnum\value{datenumber}<\value{tuffver@labmonth@startdate}\relax
    \else
    \ifnum\value{datenumber}>\value{tuffver@labmonth@enddate}\relax
      \else\tuffver@labmonth@body
    \fi
  \fi
}
\makeatother

结果是添加

\onlylabmonth{2015-04}

序言部分的结果只是labmonth环境的内容

\begin{labmonth}{2015-04}
    <stuff which should be typeset>
\end{labmonth}

正在排版。所有其他环境的内容labmonth将被丢弃。

请注意,所有labmonth环境之外的任何内容都将被排版。因此,您可以拥有一组\maketitle标准\tableofcontents缩写或其他内容,这些内容都将包括在内。

也就是说,任何仅应有条件地包含的事物都必须在labmonth环境内。

您可以在任何时候(不仅仅是在序言中)设置要排版的月份,但只有后面的内容会受到影响。任何labmonth已排版的月份都会保留,无论它们是否在请求的范围内。

因此,我建议在序言中设置开始/结束月份、年份或具体月份,因为这将确保它们具有预期的效果。

以下是基于以下代码的完整示例实验室手册的文档,由 Frank Küster 编写。

\documentclass[idxtotoc,hyperref]{labbook}% based on examplen.tex and boilerplates.tex in the package documentation by Frank Küster
\usepackage{environ,datenumber}
\makeatletter
\newcounter{tuffver@labmonth@startdate}
\newcounter{tuffver@labmonth@enddate}
\def\tuffver@labmonth@year#1-#2\null{#1}
\def\tuffver@labmonth@month#1-#2\null{#2}
\newcommand*\labmonthstart[1]{%
  \xdef\tuffver@labmonth@start@year{\expandafter\tuffver@labmonth@year#1\null}%
  \xdef\tuffver@labmonth@start@month{\expandafter\tuffver@labmonth@month#1\null}%
  \setmydatenumber{tuffver@labmonth@startdate}{\tuffver@labmonth@start@year}{\tuffver@labmonth@start@month}{01}%
}
\newcommand*\labmonthend[1]{%
  \xdef\tuffver@labmonth@end@year{\expandafter\tuffver@labmonth@year#1\null}%
  \xdef\tuffver@labmonth@end@month{\expandafter\tuffver@labmonth@month#1\null}%
  \setmydatenumber{tuffver@labmonth@enddate}{\tuffver@labmonth@end@year}{\tuffver@labmonth@end@month}{01}%
}
\newcommand*\onlylabmonth[1]{%
  \labmonthstart{#1}%
  \labmonthend{#1}%
}
\newcommand*\onlylabyear[1]{%
  \labmonthstart{#1-01}%
  \labmonthend{#1-12}%
}
\labmonthstart{1800-01}
\labmonthend{2100-12}
\environbodyname\tuffver@labmonth@body
\NewEnviron{labmonth}[1]
{%
  \edef\tempa{\expandafter\tuffver@labmonth@year#1\null}%
  \edef\tempb{\expandafter\tuffver@labmonth@month#1\null}%
  \setdatenumber{\tempa}{\tempb}{01}%
  \ifnum\value{datenumber}<\value{tuffver@labmonth@startdate}\relax
    \else
    \ifnum\value{datenumber}>\value{tuffver@labmonth@enddate}\relax
      \else\tuffver@labmonth@body
    \fi
  \fi
}
\makeatother
\usepackage[%
  backref=page,%
  pdfpagelabels=true,%
  plainpages=false,%
  colorlinks=true,%
  bookmarks=true,%
  pdfview=FitB]{hyperref}
\newcommand*{\sometext}{A rather lengthy description which is just here to use some space, so that one can see the effect of the index ranges. }
\newcommand*{\Xsometext}{\sometext\sometext\sometext\sometext \sometext\sometext\sometext\sometext\sometext\sometext}
\newcommand*{\othertext}{Some shorter Text, the cells will only grow if you're not a muggle\dots }
\newcommand*{\Xothertext}{\othertext\othertext\othertext \othertext\othertext\othertext\othertext}
\newcommand{\sdsband}{\rule{1cm}{0.15cm}}
\newcommand{\sdsbandh}{\rule[0.2cm]{1cm}{0.15cm}}
\newcommand{\sdsbandl}{\rule[-0.15cm]{1cm}{0.15cm}}
\newcommand*{\sdsgel}{%
  \begin{tabular}{cccccccc}
    \sdsband & \sdsbandl & \sdsband & \sdsbandh &
    \sdsbandh & \sdsband & \sdsbandl & \sdsband \\[0.5cm]
    \sdsbandl & \sdsband & \sdsbandh & \sdsbandl &
    \sdsband & \sdsbandl & \sdsbandh & \sdsband \\[0.5cm]
    \sdsbandh & \sdsbandl & \sdsbandh & \sdsband &
    \sdsbandl & \sdsbandh & \sdsband & \sdsbandl \\[0.5cm]
    \sdsband & \sdsbandh & \sdsbandl & \sdsbandl &
    \sdsband & \sdsbandh & \sdsbandl & \sdsbandh \\[0.5cm]
    \sdsbandl & \sdsbandl & \sdsbandh & \sdsband &
    \sdsbandh & \sdsbandl & \sdsbandh & \sdsband \\[0.5cm]
  \end{tabular}
}
\newexperiment{prep_S-peptide}{Preparation of RNase A S-peptide}
\newsubexperiment{subtilisin}[subtilisin digest]{Digestion with Subtilisin}
\newexperiment{prep?some1thing}{Preparation of purified something}
\newexperiment{lyoph-A}{Lyophilization of A}
\newexperiment{lyoph-B}{Lyophilization of B}

% \labmonthstart{2015-12}
% \labmonthend{2016-01}
\onlylabmonth{2015-04}
% \onlylabyear{2015}

\begin{document}

\frontmatter
\title{Laboratory Journal from 2015-04-22 to \dots}
\author{Jane Eager}
\maketitle

\printindex
\tableofcontents

\mainmatter

\begin{labmonth}{2014-12}

  \labday{Tuesday, Dec 22, 2014}

  \experiment{prep_S-peptide}

  End of year party!

\end{labmonth}

\begin{labmonth}{2015-01}

  \labday{Tuesday, Jan 22, 2015}

  \experiment{prep_S-peptide}

  Resolve to make better notes this year so I don't keep doing the same experiment over and over again\dots

\end{labmonth}

\begin{labmonth}{2015-04}

  \labday{Tuesday, April 22, 2015}

  \experiment{prep_S-peptide}
  \subexperiment{subtilisin}

  \Xsometext\par
  \Xsometext\par
  \Xsometext\par
  \Xsometext\par
  \begin{figure}[htbp]
    \centering
    \sdsgel
    \caption{Some very interesting SDS gel}
    \label{fig:digest-sds}
  \end{figure}

  \experiment{Expression of Hagridin in \textit{E. coli}}

  \subexperiment[Transformation with HagIV plasmid]{Transformation of hogwarts-auxotrophic \textit{E. coli} with the HagIV plasmid}

  \Xothertext\Xothertext

\end{labmonth}

\begin{labmonth}{2015-10}

  \labday{Wednesday, Oct 23, 2015}

  \experiment{prep_S-peptide}

  \subexperiment[subtilisin]{Digestion using the new batch of Subtilisin}

  \experiment{prep?some1thing}

  \experiment{Preparation of A}

  A was prepared according to the protocol in Muller \textit{et al.} and was temporarily stored in the freezer.

\end{labmonth}

\begin{labmonth}{2015-12}

  \labday{Thursday, Dec 24, 2015}

  \experiment{Preparation of B}

  B was prepared according to the protocol by Smith and Fox.

  \experiment[Lyophilization of A and B,lyoph-A, lyoph-B ]{Lyophilization of A and B}

\end{labmonth}

\begin{labmonth}{2016-01}

  \labday{Tuesday, Jan 22, 2016}

  \experiment{prep_S-peptide}
  \subexperiment{subtilisin}

  \Xsometext\par
  \Xsometext\par
  \Xsometext\par
  \Xsometext\par
  \begin{figure}[htbp]
    \centering
    \sdsgel
    \caption{Some very interesting SDS gel}
    \label{fig:digest-sds}
  \end{figure}

  \experiment{Expression of Hagridin in \textit{E. coli}}

  \subexperiment[Transformation with HagIV plasmid]{Transformation of hogwarts-auxotrophic \textit{E. coli} with the HagIV plasmid}

  \Xothertext\Xothertext

  \labday{Wednesday, Jan 23, 2016}

  \experiment{prep_S-peptide}

  \subexperiment[subtilisin]{Digestion using the new batch of Subtilisin}

  \experiment{prep?some1thing}

  \experiment{Preparation of A}

  A was prepared according to the protocol in Muller \textit{et al.} and was temporarily stored in the freezer.

  \labday{Thursday, Jan 24, 2016}

  \experiment{Preparation of B}

  B was prepared according to the protocol by Smith and Fox.

  \experiment[Lyophilization of A and B,lyoph-A, lyoph-B ]{Lyophilization of A and B}

\end{labmonth}

\end{document}

如上所述,这将仅排版 2015 年 4 月 22 日的注释,因为这是指定月份的唯一报告。

2015 年 4 月

如果我们取消注释该行

\onlylabyear{2015}

那么我们将获得 2015 年月份的所有报告。

2015

\labmonthstart{}如果使用和指定不同的范围,也会得到类似的结果\labmonthend{}

默认打印 1800 年至 2100 年的所有报告。因此,如果您正在排版亚里士多德的实验室笔记,请不要忘记,如果您将公元前年份指定为负整数,则需要更改默认值。如果您正在排版牛顿的报告,您可能只需重新定义\startyear。但是,请参阅日期编号关于涉及 1800 年之前的日期的计算的警告。

答案2

为每个月定义一个新环境。使用该 comment 包关闭除要格式化的月份之外的所有月份的编译。

与@cfr 的答案相比,这个答案不太优雅,也不太灵活,但是有效,并且提供了一些季节性的乐趣:

在此处输入图片描述

\documentclass{article}

\title{Chicken Soup with Rice}
\author{Maurice Sendak}

\usepackage{comment}
\usepackage{verse}

\newenvironment{Dec15}{}{}
\newenvironment{Jan16}{}{}

\excludecomment{Jan16}

\newcommand{\chorus}[2]{%
#1 once, #2 twice,\\
#1 chicken soup with rice.
}

\begin{document}

\maketitle

% Use \\ to start a new line only in 
% environments that know how to deal with it -
% e.g. verse, tabular, align

\begin{Dec15}
\begin{verse}
In December I will be\\
a baubled bangled Christmas tree\\
with soup bowls draped all over me.\\
\chorus{Merry}{merry}
\end{verse}
\end{Dec15}


\begin{Jan16}
\begin{verse}
In January it's so nice\\
While slippin' on the slidin' ice\\
To sip hot chicken soup with rice.\\
\chorus{Sippin'}{sippin'}
\end{verse}
\end{Jan16}

\end{document}

相关内容