1

To better organize my recipes I would like to store them in a database instead of having plenty of books being scattered all around. There are many programs to realize this by offering a GUI to either the mealmaster and/or rezkonv format (the latter is very popular in Germany, both formats are very similar). However, at some point in time I would like to create small books from these recipes, e.g., as a present for friends. This question targets the issue on how to do this properly in an automated manner.

As a first step, I would like to discuss, which of the following options is the most reasonable.

  1. Use LaTeX to parse a complete rezkonv "database" (many recipes in a single file)
  2. Use LaTeX to parse a single rezkonv recipe at a time (each recipe is one file)
  3. Use an external tool (e.g. written in Python) to create suitable LaTeX files which can be further processed by including the resulting files.

To me, the most simple one would be to go for option (2). A book is unlikely to contain more than 150+ (?) recipes and I would argue that dealing with these recipes is easier if each one of them is in a single file (e.g., adding and removing a recipe is much easier).

So let's assume the following structure:

  • main.tex includes everything required to create our cookbook
  • recipe1.rk includes a single recipe
  • recipe2.rk includes another recipe

No the question arises how to parse these files properly and allow "post-processing" within the LaTeX code (e.g., rearranging content, turning data being read into tables, applying "styles", etc). Ideally, one would be able to parse the data, extract it based on the identifiers of the specific file format (rezkonv) and finally rearrange/"print"/highlight it as desired, possibly by adding more stuff to the recipe which is not supported by the original file format (e.g., referring to other recipes that match well). Of course, adding photos and such should be possible (simply parsing the files and using them as a single page is not an option, a more 'advanced' approach is desired).

A possible realization may look like this:

...
\readrecipe{recipe1.rk}
\setstyle{soups}
\setheading{Grandma's uber-soup}
\printkey{ingredients,recipe1.rk}
% preparation time not mentioned in recipe, but we would like to have it anyway
\subsection*{Preparation}
lorem ipsum
\printkey{instructions,recipe1.rk}
...
\subsection*{Best matches}
\ref{recipe:mostdeliciousbread}
...
\readrecipe{recipe2.rk}
\setstyle{salads}
...

Whereas the style could be something like this (post by Yiannis Lazarides): Fancy chapter headings

So far, I did not do a lot of low-level programming in LaTeX. That's why I would probably go for option 3. However, I believe LaTeX should be able to do this, too. Others may also be interested in this. I would therefore like to ask for hints on how to realize this or to receive (best case) proof of concept code which could be extended. I'm willing to spend a nice bounty for good answers.

(pdflatex solutions preferred)

Edit: oh well .. here is an example:

========== 'Kalorio V4.03' (reg.) nach REZKONV

     Titel: (2) Pellkartoffeln mit Kräuterquark und Schinken
Kategorien: Gemüse
     Menge: 4 Personen


Zutaten:
      1        kg  Festkochende Kartoffeln
    1/2      Bund  Schnittlauch
    1/2      Bund  Glatte Petersilie
            Etwas  Frisches Basilikum zur Deko
      1            Rote (ungarische) Spitzpaprika
      1            Grüne (ungarische) Spitzpaprika
    250     Gramm  Quark mit 20% Fett
    250     Gramm  Quark mit 40% Fett
      2            Schalotten
      1      Essl. Kümmel
    150     Gramm  Saure Sahne (oder süfle Sahne)
                   Salz, Pfeffer
      1     Prise  Muskat
      8  Scheiben  Schinken, gekocht oder geräuchert
      4            Tomaten
      1     Stück  Gurke

======================QUELLE======================
            Christian Schill

Zubereitung:
Die Kartoffeln waschen und in der Schale in reichlich Wasser (1%
Salz) mit dem Kümmel ca. 20 Minuten garen.

[left out some text here]

Kartoffeln abgieflen, schälen und mit dem Kräuterquark und dem
Schinken anrichten.

Zubereitung: etwa 30 Minuten.

:Stichworte     : Kartoffeln
:Stichworte     : Gemüse
:Fingerprint    : 30950473,-1032086772,Kalorio


=====
  • Bit hard to suggest anything without knowing anything at all about the format of the files you want LaTeX to parse. Presumably they are plain text files? What else? – cfr Feb 9 '14 at 0:15
  • Potentially useful: sourceforge.net/projects/rezkonv2latex sourceforge.net/projects/rezkonv2latex.berlios/… (I can't read the description, though). – cfr Feb 9 '14 at 0:26
  • Unless you want to list them more-or-less verbatim, I'd think it would be easy to use other tools to pre-process them for use by LaTeX. You could potentially have LaTeX call those external tools, of course. Or you could create a script to run the tools and LaTeX etc. as required. Is there any particular reason you want to parse the files directly with LaTeX? Note: I'm not saying this can't be done with TeX. Just I personally would guess it would be easier not to. I'm not sure you really can do low-level programming in LaTeX. Wouldn't that be TeX?! – cfr Feb 9 '14 at 0:33
  • 3
    go for option 3 – David Carlisle Feb 9 '14 at 1:20
  • @cfr: I have tested both of them and neither is working. – user26372 Feb 9 '14 at 10:33
3

Okay, here's the result of today's fun project:

The call rz2tex file of the following bash script (e.g. with cygwin on Windows)

#!/bin/bash
#
rzfile="$1"
typeset -i start
typeset -i ende
#
rztitel=`grep -e 'Titel:' "$rzfile" | cut -d':' -f2 | sed -e 's/^ *//'`
rzkat=`grep -e 'Kategorien:' "$rzfile" | cut -d':' -f2 | sed -e 's/^ *//'`
rzmenge=`grep -e 'Menge:' "$rzfile" | cut -d':' -f2 | sed -e 's/^ *//'`
rzstichwort=` grep -e ':Stichwort' "$rzfile" | cut -d':' -f3 | sed -e 's/^ *//' | tr '\n' ',' | sed -e 's/,$//' -e 's/,/, /'`
start=`grep -ne 'Zutaten:' "$rzfile" | cut -d':' -f1`
ende=`grep -ne '==QUELLE==' "$rzfile" | cut -d':' -f1`
((ende++))
rzquelle=`sed -ne "$ende p" "$rzfile" | sed -e 's/^ *//'`
#
((start++))
((ende--))
((ende--))
sed -ne "$start,$ende p" "$rzfile" | sed -e '/^\s*$/d' >zutaten.txt
start=`grep -ne 'Zubereitung:' "$rzfile" | head -n 1 | cut -d':' -f1`
ende=`grep -ne ':Stichworte' "$rzfile" | head -n 1 | cut -d':' -f1`
((start++))
((ende--))
sed -ne "$start,$ende p" "$rzfile" >zubereitung.txt
#
exec 1> rezept.tex
echo "\documentclass[fontsize=9pt,DIV=12]{scrartcl}"
echo "\usepackage[utf8x]{inputenc}"
echo "\usepackage{multicol}"
echo "\setlength{\parindent}{0pt}"
echo "\begin{document}"
echo "\section*{$rztitel}"
echo "Kategorien: $rzkat\\\\"
echo "Menge: $rzmenge\\\\"
echo "\subsection*{Zutaten:}"
echo "\begin{multicols}{2}"
echo "\begin{itemize}"
while read line
do 
  rzvalue=`echo $line | cut -d ' ' -f1`
  rzunit=`echo $line | cut -d ' ' -f2`
  rzzutat=`echo $line | cut -d ' ' -f3-`
  echo "\item $rzvalue $rzunit $rzzutat"
done < zutaten.txt
echo "\end{itemize}"
echo "\end{multicols}"
echo "\subsection*{Zubereitung:}"
cat zubereitung.txt
echo "\subsection*{Stichworte: $rzstichwort}"
echo "\subsection*{Quelle: $rzquelle}"
echo "\end{document}"

produces this tex source:

\documentclass[fontsize=9pt,DIV=12]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage{multicol}
\setlength{\parindent}{0pt}
\begin{document}
\section*{(2) Pellkartoffeln mit Kräuterquark und Schinken}
Kategorien: Gemüse\\
Menge: 4 Personen\\
\subsection*{Zutaten:}
\begin{multicols}{2}
\begin{itemize}
\item 1 kg Festkochende Kartoffeln
\item 1/2 Bund Schnittlauch
\item 1/2 Bund Glatte Petersilie
\item Etwas Frisches Basilikum zur Deko
\item 1 Rote (ungarische) Spitzpaprika
\item 1 Grüne (ungarische) Spitzpaprika
\item 250 Gramm Quark mit 20% Fett
\item 250 Gramm Quark mit 40% Fett
\item 2 Schalotten 
\item 1 Essl. Kümmel
\item 150 Gramm Saure Sahne (oder süße Sahne)
\item Salz, Pfeffer 
\item 1 Prise Muskat
\item 8 Scheiben Schinken, gekocht oder geräuchert
\item 4 Tomaten 
\item 1 Stück Gurke
\end{itemize}
\end{multicols}
\subsection*{Zubereitung:}
Die Kartoffeln waschen und in der Schale in reichlich Wasser (1%
Salz) mit dem Kümmel ca. 20 Minuten garen.

[left out some text here]

Kartoffeln abgießen, schälen und mit dem Kräuterquark und dem
Schinken anrichten.

Zubereitung: etwa 30 Minuten.

\subsection*{Stichworte: Kartoffeln, Gemüse}
\subsection*{Quelle: Christian Schill}
\end{document}

enter image description here

You can of course map the shell variables to other LaTeX structures, e.g. in a dedicated recipe class!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.