Directory structure for a book project
Overview of the directory structure
Directory structure within a chapter
The total directory structure
The book
directory
Newcommands
Assembling different pieces to a book
Organization of DocOnce chapter files
Compiling a chapter requires a wrapper file with title, author, ...
Figures and source code
Assembly of chapters to a book
A book.do.txt
file
The book file relies much on running preprocessors
The book
directory must be coupled to source and figure directories
About figures when publishing HTML
Tools
Making a new chapter
Compiling a chapter
Compiling the book
Study guides and slides
Why is it so challenging to convert a chapter to slides?
Slide directory
The lectures_ch2.do.txt
file
The requirements to a slide collection
doc
: documentationdoc/src
: (DocOnce) source for documentationdoc/src/chapters
: source for individual chaptersdoc/src/book
: source for the bookdoc/pub
: published (compiled) documents in specific formatsdoc/web
: entry point (index.html
) for GitHub web pages
Can have lots of chapters and more than one book
directory if
multiple books are relevant.
Each chapter has a short nickname used in file and directory names.
ch2
ch2
: DocOnce source files .do.txt
ch2/src-ch2
: source files for program programs, especially
those to be copied into .do.txt
filesch2/fig-ch2
: figuresch2/mov-ch2
: moviesch2/exer-ch2
: answers to exercises
The directories src-ch2
, fig-ch2
, mov-ch2
, and similar may have
any subdirectory structure, but the names should as indicated here since
the setup for DocOnce books has many tools relying on the naming convention.
Here is a big project:
doc
src
chapters
ch2
fig-ch2
src-ch2
mov-ch2
exer-ch2
ch3
fig-ch3
src-ch3
mov-ch3
exer-ch3
book1
book2
pub
chapters
ch2
html
pdf
ipynb
ch3
html
pdf
ipynb
book
book
directory book.do.txt
book.do.txt
includes chapters from ../chapters/ch2/ch2.do.txt
, etcnewcommands*.tex
are treated by DocOnce as files
with definitions of newcommands for LaTeX mathematicsdoconce format
is runnewcommands.p.tex
for all chapters.p.tex
indicates that it can be run by preprocess and contain
different newcommand definition for LaTeX and MathJax
Example on doc/chapters/newcommands.p.tex
:
%% #if FORMAT in ("latex", "pdflatex")
%% Use footnotesize in subscripts
\newcommand{\subsc}[2]{#1_{\mbox{\footnotesize #2}}}
%% #else
%% In MathJax, a different construction is used
\newcommand{\subsc}[2]{#1_{\small\mbox{#2}}}
%% #endif
make.sh
runs
typically
preprocess -DFORMAT=pdflatex ../newcommands.p.tex > newcommands.tex
# make latex versions
preprocess -DFORMAT=html ../newcommands.p.tex > newcommands.tex
# make html versions
Do not use newcommands for general typesetting commands, use Mako functions instead - they work for all output formats.
ch2
ch2.do.txt
ch2.do.txt
may contain all the text or just include several
files: part1.do.txt
, part2.do.txt
, part3.do.txt
ch2.do.txt
- otherwise
that file cannot be included in a book
ch2.do.txt
:
# #include "part1.do.txt"
# #include "part2.do.txt"
# #include "part3.do.txt"
To compile a stand-alone document for the chapter, create
main_ch2.do.txt
:
TITLE: Some chapter title
AUTHOR: A. Name Email:somename@someplace.net at Institute One
AUTHOR: A. Two at Institute One & Institute Two
DATE: today
TOC: on
# Externaldocuments: ../ch3/main_ch3, ../ch4/main_ch4
# #include "ch2.do.txt"
======= References =======
BIBFILE: ../papers.pub
fig-ch2
: figuressrc-ch2
: source code for program files
Important that figure and source code files have chapter-unique names
when combining all files into a book. Use fig-nickname
and src-nickname
.
Optional directories:
mov-ch2
: movies in various formatsexer-ch2
: answers to exercises, project work, etc.
DocOnce = Document Once, Include Anywhere
book.do.txt
for including chapters in a bookbook.tex
(!)book.tex
to the relevant
.do.txt
filebook.do.txt
file
TITLE: This is a book title
AUTHOR: A. Name Email:somename@someplace.net at Institute One
AUTHOR: A. Two at Institute One & Institute Two
DATE: today
TOC: on
========= Preface =========
label{ch:preface}
# #include "../chapters/preface/preface.do.txt"
========= Heading of a chapter =========
label{ch:ch2}
# #include "../chapters/ch2/ch2.do.txt"
# Similar inclusion of other chapters
========= Appendix: Heading of an appendix =========
label{ch:somename}
# #include "../chapters/nickname/nickname.do.txt"
======= References =======
BIBFILE: ../papers.pub
# #include
and # #if
tests are seen in
tmp_preprocess__book.do.txt
(input to mako
)tmp_mako__book.do.txt
(input to doconce
translation)book
directory must be coupled to source and figure directories Running
Terminal> doconce format pdflatex book [options]
will most likely involve constructs like
@@@CODE src-ch2/myprog.py fromto: def test1@def test2
but pdflatex
sees no book/src-ch2
directory! A local link
resolves the problem:
Terminal> ln -s ../chapters/ch2/src-ch2 src-ch2
Similar problems for figures!
Terminal> ln -s ../chapters/ch2/fig-ch2 fig-ch2
Auto-generation of all links (if chapters=
is set correctly in scripts.py
):
>>> import scripts
>>> scripts.make_links()
<img src=fig-ch2/fig1.png>
type of tags in the HTML codefig-ch2
subdirectorychapters/ch2/fig-ch2
to the directory where the HTML files are published
doc/chapters
bash mkdir.sh nickname
rules
to see syntax/detailsnickname/*.do.txt
files, programs in src-nickname
,
place figures in fig-nickname
make.sh
if necessarybash make.sh
../chapters/nickname/nickname.do.txt
with chapter heading
in doc/src/book/book.doc.txt
To LaTeX/PDF:
Terminal> bash make.sh
To HTML:
Terminal> bash ../make_html.sh main_nickname.do.txt
The doc/src/chapters/make.sh
script is quite general and can be edited
according to your layout preferences of the LaTeX documents.
There is also a script doc/src/chapters/make_html.sh
for making
HTML versions of the chapter. Just call this as
Terminal> bash ../make_html.sh main_mychap
Three HTML versions with an index.html
table of contents are generated.
Go to book
directory and produce LaTeX/PDF book by
Terminal> bash make.sh
Terminal> bash make.sh nospell # turn off spell checking
About book styles and tools:
scripts.py
has function pack_src
for packing all the
src-*
directories in a tarfile for book readerspack_Springer.sh
packs all needed LaTeX book files for publishing
with Springer
Balance:
Many iterations and use of slides in teaching over and over again are needed!
For a chapter ch2
,
slides-ch2
ch2/part1.do.txt
has its slide counterpart in
ch2/slides-ch2/part1.do.txt
ch2/lectures_ch2.do.txt
includes all relevant slides-ch2/*
files and
is the main file for the slide collectionCompile slides:
Terminal> bash ../make_lectures.sh lectures_ch2.do.txt
Note the possibility to turn the TOC
on and off: Beamer has its own
table of contents, while HTML5 slides may benefit from having one.
lectures_ch2.do.txt
file
TITLE: Study Guide: Some title
AUTHOR: Author Name Email:somename@someplace.net at Institute One
DATE: today
# #ifdef WITH_TOC
!split
TOC: on
# #endif
# #include "lec-ch2/part1.do.txt"
# #include "lec-ch2/part2.do.txt"
# #include "lec-ch2/part3.do.txt"
Tree purposes:
Rules: