# Difference between revisions of "Biochemistry textbook"

Jörg Hagmann

I wrote a biochemistry textbook in ConTeXt and would like to share the code. There is nothing special in it, but it might be useful to beginners. The book was compiled in Mk II, of course. Anything slightly non-trivial was contributed by experts, especially Wolfgang. You can download 8 sample pages from "http://www.ogbasel.ch/hagmann_biochemistry.pdf" LINK TEMPORARILY UNAVAILABLE.

Encoding. I wrote in Emacs, encoding the text in iso-latin-1:

\enableregime [il1]


Language specific stuff. The book is written in German. By default, German quotes would show up as something like ,some text', quotations would be between ", the first one at the bottom of the line, the second one high (don't know how to show that here). I wanted "English" quotes and guillemets for quotations:

\setuplanguage[de]
[leftquote=\upperleftsinglesixquote,rightquote=\upperrightsinglesixquote,
leftquotation=\leftguillemot,rightquotation=\rightguillemot]
\mainlanguage [de]


Fonts. I proposed LinLibertine, but the publisher thought that too "unorthodox". Too bad, but here's the setup for Times:

\usetypescript[times][ec]
\setupbodyfont[times,11pt]


Greek. I used the greek module. You can write "real" Greek, with all the accents, like this: \greek{p'anta <re~i} (See Maps article by Willi Egger):

\usemodule[greek]


Units. Units like µg, mg etc. can be consistently set with the units module (see Contextgarden page). But I found that, sometimes, the character sizes didn't match well with the text (different font, I suppose?), and I therefore often simply used "mg" instead of "\Milli\Gram" etc.

\usemodule[units]


Colours. I used two kinds of red: "red", which is predefined, and a lighter red I defined myself. Colors need to be "set up":

\setupcolors[state=start]
\setupcolor[rgb]
\definecolor[lightred][r=1,g=0.85,b=0.85]


Papersize.

\definepapersize[MyBook][width=17cm,height=24cm]
\setuppapersize[MyBook][MyBook] % Prints on paper the size of MyBook
%\setuppapersize[MyBook][A4] %Would print MyBook-size pages on A4 paper


Layout. I know that the following layout is not as generous as it should be, but this is what the publisher wanted; the wide cutspace is needed for margin figures:

\setuplayout[location=middle,
topspace=1.3cm,
width=middle,
cutspace=4.5cm,
rightmargindistance=0.4cm,
leftmargindistance=0.2cm,
backspace=1.2cm,
height=fit,
rightmargin=2.5cm,
leftmargin=1cm,
bottomspace=2cm,
footer=0.8cm,
setup=strict]


Manual adaptations of the layout. Because of the nature of the text (many itemizations, figures, tables and such), I had to manually adjust the number of lines on some pages, e.g.:

\adaptlayout[14][lines=+1]


Displaying frames etc.. In order to know what you are doing, comment/uncomment the following 4 lines:

% \showgrid
% \showframe
% \showsetups
% \showlayout


Page numbering. Sorry---no headers or footers. Just simple page number at bottom centre.

\setuppagenumbering[alternative=doublesided,location=footer]


Tolerance. This was one of the first suggestions I got to a question I asked. Didn't change it nor play with it:

\setuptolerance[tolerant, stretch]


Paragraphs. The paragraphs are not indented, but separated by whitespace:

\setupwhitespace[medium]


Footnotes. I used symbols for footnotes (conversion), starting with the same symbol on a new page:

\setupfootnotes[way=bypage, conversion=set 2]


Chapters and sections. Don't remember what this was for:

\definepagebreak[chapter][yes,footer,right]


Bookchapters. Red chapter number, set off from title text by a vertical bar. Chapters always start on a right (odd) page. If the even page preceding it is empty, there should be no page number. I tried "before={\ifodd\realpageno\else\page[empty]\fi}" which works if "page=yes"; but it messed up other things, so I ended up by removing page numbers manually in "Acrobat".

\def\BookchapterCommand#1#2{\framed[frame=off,rightframe=on]{#1\space}\framed[frame=off]{\space#2}}


Section titles. Red numbers and black title on top of a gray background. The problem was long titles: how to get the text properly aligned (if you don't do anything, the text of the second line will be left-aligned, under the section number). The solution was provided by Wolfgang Schuster:

\def\SectionCommand#1#2%
{\framed
[frame=off,
width=\textwidth,
align={right},
background=color,
backgroundcolor=lightgray]
\vtop{\hsize\dimexpr\hsize-.061\textwidth-1em\relax\begstrut#2
\endstrut}}}



Subsections. "sans serif" on a gray background, but no numbering. The publisher wanted some distance between the left and the beginning of the subsection text, so I used Wolfgang's trick again:

\def\SubsectionCommand#1#2%
{\framed
[frame=off,
width=\textwidth,
align={right},
background=color,
backgroundcolor=lightgray]
{\hbox to.011\textwidth{\strut#1}\vtop{\hsize\dimexpr\hsize-.011\textwidth-1em\relax\begstrut#2
\endstrut}}}



Subsubsections. Italic, no distance between subsubsection title and following paragraph. There is also an attempt to avoid subsubsection titles on the last line of a page, but if I remember correctly that didn't (always?) work:

\setuphead[subsubsection][command=,style=slanted,number=no,before={\blank[big]},before={\testpage[1]},after=\nowhitespace]


Legends. More space after the legends:

\setupfloats[spaceafter=3*medium]


Tables I. I used Tables (\starttables ... \stoptables), simply because that was the first method I encountered. This is how I set up fontsize of the tables and the captions. "\setupinterlinespace" adjusts the interlinespace of the captions to the (smaller) fontsize (here, the exact distance was what the publisher wanted; otherwise "\setupinterlinespace" without any specifications is enough).

\setuptables[bodyfont=small]
\setupcaption[table][style={\ssx\setupinterlinespace[line=2.5ex]},align=left]


Tables II. Tables of width <0.5 times textwidth are automatically placed at the inner margin (Instructions can be found in "Details.pdf").

\setupfloat[table][criterium=0.5\textwidth,default=inner]


Figures I. Same story as tables.

\setupcaption[figure][style={\ssx\setupinterlinespace[line=2.5ex]},align=left]


Figurs II. Figures and tables larger than textwidth (maximum: textwidth + marginwidth + what's between them) should stick out into the (outer, wide) margin:

\definefloat[Bigfigure][Bigfigures][figure]
\setupfloat[Bigfigure][location=inner]

\definefloat[Bigtable][Bigtables][table]
\setupfloat[Bigtable][location=inner]


Figures III. I had many figures in the outer margin (unnumbered, unlabelled). But some were a bit too wide (>2.5cm); I wanted them filling the margin and sticking into the text; I called them "vignettes":

\definefloat[vignette][figure]
\setupfloat[vignette][leftmargindistance=-\outermargintotal,rightmargindistance=-\outermargintotal,default={outer,none,low}]
\setupcaption[vignette][number=no]


Framed texts. I had three types of framed text which I named "Story", "MySummary" and "Oddity". You put the text between "\startStory...\stopStory" etc. You can see what they look like in the pdf files:

\definestartstop[Story][before={\setupbackground[style=\tfx,background=color,backgroundcolor=white,frame=on,framecorner=rectangular,framecolor=black,rulethickness=0.5pt,topoffset=0.25cm,bottomoffset=0.25cm,leftoffset=0.25cm,rightoffset=0.25cm,before={\blank[big]}]\startbackground\switchtobodyfont[10pt]},after=\stopbackground]

\definestartstop[MySummary][before={\setupbackground[background=color,backgroundcolor=lightgray,backgroundcorner=rectangular,frame=off,topoffset=0.3cm,bottomoffset=0.3cm,leftoffset=0.5cm,rightoffset=0.5cm,before={\blank[big]}]\startbackground\Zus},after=\stopbackground]



Text in the margin. sans serif, smaller size and leftaligned(!). Again: "\setupinterlinespace".

\setupinmargin[align=right,style=\ss\tfx\setupinterlinespace]


Itemizations. The publisher wanted them left(!)aligned:

\setupitemize[align=right]


Appendices. The setups go between "\startsectionblockenvironment[appendix]...\stopsectionblockenvironment".

\startsectionblockenvironment[appendix]


Appendices. One of the appendices consisted of endless lists of diseases with the corresponding enzyme defects. A case for "\starttabulate...\stoptabulate", leftaligned:

\setuptabulate[align=right,split=yes]


Chapters, sections, etc. Appendices got characters instead of numbers (A, B, etc.). The design made use of the setups defined above, with some differences (numbering, e.g.).

\definepagebreak[chapter][yes,footer,right]



Appendix figures. I wanted the Figures in the appendix framed, but not numbered:

\definefloat[BigFramedFigure][BigFramedFigures][figure]
\setupfloat[BigFramedFigure][location=inner,frame=on,offset=2pt]
\definefloat[FramedFigure][FramedFigures][figure]
\setupfloat[FramedFigure][frame=on,offset=2pt]

\stopsectionblockenvironment


Index. The following code will produce an index with red, capital characters heading the beginning of a new section. (Try it, if you don't know what I mean).

\setupregister[index][color=red,alternative=A]


Table of contents. Chapters and sections only, looks (more or less) as follows: 3 Glycolysis and Gluconeogenesis........ 31 3.1 Glycolysis ............................ 31 3.2 Gluconeogenesis ....................... 35

\setupcombinedlist[content][level=2,alternative=c]
\setuplist[chapter][style=bold]


Input files. The path to the (pdf) figures, the names of the figures, and additional stuff such as width were defined in file. So were some definitions I'm using for othere projects:

\input ../path/to/figures_book.tex
\input ../path/to/Mydefinitions


Organisation of the project. I realise that there are sophisticated ways of organising "projects", but I didn't bother. I simply stuffed the single chapters between \starttext ... \stoptext. The file "index.tex" contains the following text: \chapter{Index}\switchtobodyfont[10pt]\placeindex. The rest of my setupfile therefore looks as follows:

\starttext

\startfrontmatter
\setuppagenumbering[conversion=romannumerals] % Pages of TOC etc numbered i, ii, etc.
\completecontent
\input /path/to/acknowledgments.tex
\stopfrontmatter
\startbodymatter
\setuppagenumbering[conversion=]
% \setuppagenumber[number=5]  % mkii
\setcounter[userpage][5]      % mkiv

\input /path/to/chapter_1.tex
\input /path/to/chapter_2.tex
\input /path/to/chapter_3.tex
% ... etc.

\stopbodymatter

\startappendices
\setupcombinedlist[content][level=1]% sections etc. of appendices not in TOC
\input /path/to/appendix_1.tex
\input /path/to/appendix_1.tex
\input /path/to/appendix_1.tex
% ... etc.

\input /path/to/index.tex
\stopappendices

\stoptext