GeneralRecipe in a Book

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
DonutMan
Posts: 3
Joined: Wed Apr 03, 2013 6:03 pm

Recipe in a Book

Post by DonutMan »

Hello,

I would like to insert recipe in a book so that I could refer to them as "Recipe 1", "Recipe 2" etc...

I found this code on the internet that I would like to adapt because I don't want to define a new document class. So I just want a new environnement definition in which I could write my recipe.

Here a example (as short as possible but still quite long... sorry...)

Code: Select all

\documentclass[12pt,a4paper]{book}
\usepackage[francais]{babel}
\usepackage[applemac]{inputenc}

\usepackage{graphicx}
\usepackage{array}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{vmargin}
\setmarginsrb{2.5cm}{2cm}{2cm}{2cm}{10mm}{6mm}{0cm}{10mm}

\usepackage{manfnt}
\usepackage{stmaryrd}
\usepackage{color}
\usepackage{marvosym}
\usepackage{nicefrac} %Pour les fractions
\usepackage{multicol} % Pour les deux colonnes dans les ingrédients

\pagestyle{empty}

%Commandes "utiles"
\newcommand{\puces}{$\leftslice$}
\newcommand{\lpage}{15cm}
\newcommand{\hpage}{15cm}
\newcommand{\niveaugris}{.90}

\definecolor{gris}{gray}{\niveaugris}
\newcommand{\rechead}
    {\centering\normalfont\Large\sffamily\bfseries}

\newcommand{\bsi}[2]{\fontsize{#1}{#2}\usefont{T1}{pbsi}{xl}{n}}
\renewcommand{\rechead}{\centering\bsi{24pt}{30pt}}

\renewcommand{\subsubsection}
    {\@startsection{subsubsection}{3}{\z@}%
    {-5ex\@plus -1ex \@minus -.2ex}%
    {1.5ex \@plus .2ex}%
    {\rechead}}

\newcommand{\recette}[1]{\subsubsection{#1}%
    \vspace{.1cm}
    \hrule height0.75pt width\hsize\vspace*{1\p@}%
    \hrule height0.25pt width\hsize%
    \nobreak
    \vskip\parskip \vspace{.3cm}}

\newcommand{\inghead}{\relax}

\newcommand{\temps}[2]
    {{\list{}{\rightmargin 1em\leftmargin 1em}%
\item[]\textit{\textbf{\huge \Clocklogo \normalsize \hspace{\stretch{1}} Pr\'eparation} : #1} \hspace{\stretch{2}} \textit{\textbf{Cuisson} : #2}\endlist}%
    \vspace{.2cm}\hrule height0.25pt width\hsize \vspace{.2cm}}
   
\newcommand{\ingredients}[2][]
    {{\list{}{\rightmargin 1em\leftmargin 1em}%
    \item[]\textit{\textbf{Ingr\'edients #1}: \vspace{-.3cm}\begin{multicols}{2}\begin{itemize}\renewcommand{\labelitemi}{\puces} #2 \end{itemize}\end{multicols}}\endlist}%
    \vspace{.2cm} \hrule height0.25pt width\hsize \vspace{.3cm}}

\newenvironment{nouvellerecette}%
    {%\newpage
     \setbox0=\hbox\bgroup
     \begin{minipage}[!h][\hpage][t]{\lpage}\vspace{.5cm}
    }%
    {%
     \end{minipage}
     \egroup
     \fcolorbox{gris}{white}{\box0}
    }

\newcommand{\degrees}{$^\circ$}
\newcommand{\attention}[1]{\vspace{.3cm} \textdbend  #1}

\pagestyle{empty}

\begin{document}

toto

\begin{nouvellerecette}
\recette{Recipe one}
\temps{15 minutes + 24 heures}{1 heure}

\ingredients[(for 40 pieces) ]{
\item $\nicefrac{1}{2}$ milk liter
\item 1 salt
\item 2 eggs
}

Just melt all the ingredients together.

\attention{Exemple of warning}

\end{nouvellerecette}

\end{document}
I have the following error :

Code: Select all

) [1{/usr/local/texlive/2009/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
! You can't use `\spacefactor' in internal vertical mode.
\@->\spacefactor 
                 \@m 
l.85 \nouvellerecette{Recipe one}

! Missing $ inserted.
<inserted text> 
                $
l.85 \nouvellerecette{Recipe one}
Do you have any idea ?


Thanks a lot :)
Donut

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Recipe in a Book

Post by localghost »

Perhaps you should take a look at a package like xcookybooky before you try to reinvent the wheel [1].

By the way, the vmargin package is obsolete. Use geometry instead to set up the paper and page dimensions.


[1] CTAN: Topic cooking


Best regards and welcome to the board
Thorsten
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Recipe in a Book

Post by cgnieder »

Hi Ddonut,

Welcome to the LaTeX community!

There's a quick fix to the error: since the code is using internal commands whose names contain @ it needs to be made a letter first. So put \makeatletter at the beginning of the definitions and add \makeatother at the end of them to make @ unusable in command-names again. Also (but totally unrelated) you should add \usepackage[T1]{fontenc} at the beginning of the document, IMHO.

Regards
site moderator & package author
DonutMan
Posts: 3
Joined: Wed Apr 03, 2013 6:03 pm

Recipe in a Book

Post by DonutMan »

Hi all,

thank you very much for yours answers.

I didn't know xcookybooky package. It seems interesting even if the final result is less pretty than the recipe class.

In fact my question should have been this:

Since the recipe class defines a whole new document class, how could I do to use it as a new environment? I don't know if it's easy to do that.

I want to use it as a new environment because I don't want to write a whole recipes book (the aim of the recipe class), but only write a regular document with some recipes written in it. So I don't want that class to change some internal options in my document.

Thanks a lot :)

Donut
Post Reply