Biochemistry textbook

From ConTeXt wiki

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 "".

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:

\mainlanguage [de]

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


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):


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.


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



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


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.:


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.


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:


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:


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".


New: This and the following definitions don't work with recent (mkIV) versions of context. Instead, use

\define[2]\YourCommand{\framed[frame=off, etc...code as before}

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 (but see "New" above):

     {\hbox to.011\textwidth{}\hbox to.05\textwidth{\strut#1}\quad


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 (but see "New" above):

     {\hbox to.011\textwidth{\strut#1}\vtop{\hsize\dimexpr\hsize-.011\textwidth-1em\relax\begstrut#2


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:


Legends. More space after the legends:


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).


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


Figures I. Same story as tables.


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



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":


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:




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


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


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


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


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.).



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



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).


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


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:


\setuppagenumbering[conversion=romannumerals] % Pages of TOC etc numbered i, ii, etc.
\input /path/to/acknowledgments.tex
% \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.


\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