4

I am using this labbook template:

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

While originally designed for lab work I am using it to keep a daily record of what I do at work (tech job). I currently have it set up where I have a seperate document for each month. The following example has just a few days taken mostly from the template example document, but contains all the important structures of my document.

\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}

I would much prefer to keep the .tex document for these notes on an ongoing (from now until forever) or failing that a yearly basis in order to maintain searchability and at the end of each month produce a pdf for that month.

I would also very much like to avoid having to create a monthly template document for this and copying the relevant section to a new .tex file.

I am using MiKTeX 2.9 with a TeXworks 0.4.6 front end. I use pdfLaTeX to do the conversion to pdf

Is there a way to tell the interpreter to just do a portion of the document and ignore the rest?

5
  • Have you looked at \includeonly ? Dec 19, 2015 at 0:59
  • @EthanBolker I had not, until just now. It seems to me that \includeonly would allow my to take many tex files and generate one resulting pdf. This is the opposite of what I want. I want to maintain a single long tex document and be able to produce a pdf that contains only a specified portion. So I keep a monthly archive in pdf format but maintain a complete searchable tex document
    – Tuffwer
    Dec 19, 2015 at 1:03
  • Welcome! Please can you provide a minimal working example (MWE)? This will make it much easier to help you and will help to ensure than answers actually work for you. It isn't clear to me, for example, how your document is arranged. Your question should not rely on an external link as those change all the time and your question will be useless to others in the future if the link breaks or the contents changes.
    – cfr
    Dec 19, 2015 at 1:18
  • @cfr I'll attempt to edit your suggestions into the post, If I may ask though what is the best way to cite a package I'm using for a particular purpose? I only really intended the link to provide a citation to the package, and didn't realize the answer would be tailored quite so specifically to the structure of my document.
    – Tuffwer
    Dec 20, 2015 at 6:49
  • If the package is included in the standard TeX distributions (TeX Live, MikTeX) then you can just use it in your minimal example. As far as I know, that's citation enough. If the package is not a standard one, you should also provide a link. Sometimes people also link to the package pages on CTAN for standard packages, but that isn't essential. It's needed for non-standard packages as people otherwise don't know where to find them.
    – cfr
    Dec 20, 2015 at 20:31

2 Answers 2

5

Update: The new version uses datenumber. If I've done it correctly, it might even work as advertised this time....


Here's a method using the package environ to define a new environment, labmonth. The user interface works as follows:

  • laboratory notes are written within the scope of the labmonth environment, which takes one mandatory argument which should specify the year and month in YYYY-MM form;

  • \onlylabmonth{YYYY-MM} will result in only the contents of the specified labmonth environment being typeset;

  • \onlylabyear{YYYY} will result in the contents of the only those labmonths which are part of the specified year being typeset;

  • \labmonthstart{YYYY-MM} prevents earlier labmonths from being typeset;

  • \labmonthend{YYYY-MM} prevents later labmonths from being typeset.

The idea is that \labmonthstart{YYYY-MM} sets the first desired month and \labmonthend{YYYY-MM} sets the last desired month. \onlylabmonth{YYYY-MM} and \onlylabyear{YYYY-MM} are convenience wrappers for cases where exactly one month or exactly one year of notes should be typeset.

The code to be added to the preamble is as follows:

\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

The upshot is that adding

\onlylabmonth{2015-04}

to the preamble results in the contents of just the labmonth environment

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

being typeset. The contents of all other labmonth environments will be discarded.

Note that anything outside all labmonth environments will be typeset regardless. So you can have a \maketitle or \tableofcontents or standard set of abbreviations or whatever and those will be included.

That is, anything which should be included only conditionally must be within a labmonth environment.

You can set the month(s) you want to typeset at any point (not just in the preamble) but only later content will be affected. Any labmonths already typeset will remain regardless of whether they are within the requested range.

For this reason, I recommend setting the start/end months, year or specific month in the preamble as that will ensure they have the expected effect.

Here's a complete example based on code from labbook's documentation, written by 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}

As written, this will typeset only the 22nd April, 2015 notes because this is the only report in the specified month.

April 2015

If we uncomment the line

\onlylabyear{2015}

then we will get all reports from months in 2015.

2015

Similar results apply if a different range is specified using \labmonthstart{} and \labmonthend{}.

The default is to print all reports from the year 1800 to the year 2100. So, if you are typesetting laboratory notes from Aristotle, don't forget that you will need to change the defaults if you are specifying years BCE as negative integers. If you are typesetting Newton's reports, you may just be able to redefine \startyear. However, see datenumber's warning concerning calculations involving dates prior to 1800.

6
  • Great! Glad it helped.
    – cfr
    Dec 20, 2015 at 20:32
  • 1
    I attempted to use this to create a date range from 2015-12 to 2016-01 using the provided commands. I got a blank document (It had the front matter, but was empty otherwise.) After closely reading the environment definition I believe the provided date range passes the first two ifnum statements (years) but the next two ifnum statements (months) cause it to determine I'm asking for an end date that occurs before my start date. The logic doesn't handle the fact that months start over with a new year.
    – Tuffwer
    Jan 12, 2016 at 0:54
  • I read that ifnum can only perform one test at a time so am currently looking into how to write the logic, but I figured you might want to know so you could update your answer to include the month count wrap around, or add a disclaimer warning about the lack of automatic wrap-around handling for month numbers. (of course my assumption could be totally wrong here and there is nothing wrong with your environment)
    – Tuffwer
    Jan 12, 2016 at 0:56
  • 1
    @Tuffwer Thanks for letting me know. It should work now. I did something slightly different as the \ifnums seemed to be getting out of hand. It now uses datenumber and should work as advertised. As long as you don't have any laboratory notes prior to the nineteenth century, anyway.
    – cfr
    Jan 12, 2016 at 2:55
  • 1
    I can confirm that it's working as advertised
    – Tuffwer
    Jan 12, 2016 at 21:00
3

Define a new environment for each month. Use the comment package to turn off compilation for all but the month you want to format.

This answer is a lot less elegant and a lot less flexible than @cfr 's, but works, and provided some seasonal fun:

enter image description here

\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}
5
  • I will look into this, thank you for the suggestion
    – Tuffwer
    Dec 19, 2015 at 1:09
  • Don't you get warnings about bad boxes with that code? Maybe the verse package would help?
    – cfr
    Dec 20, 2015 at 1:38
  • @cfr If I were serious about typesetting poetry I'd use that package. All I wanted here was an MWE. The one-a-month requirement reminded me of the poem. I haven't even bothered to make the second appearance of the argument to the chorus lower case. Dec 20, 2015 at 2:09
  • The thing is, it is bad to break lines with \\ except in particular environments. I realise the verse is incidental but, still, you must generate lots of warnings. And it is bad to provide \\ for new lines as example code.
    – cfr
    Dec 20, 2015 at 2:30
  • @cfr You are right. There's never a good excuse for poor style. Edited. Thanks. Dec 20, 2015 at 14:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .