DocOnce offers strong support for admonition environments, such as warning boxes, notification boxes, question boxes, and summary boxes. The boxes normally have an icon, a heading, and may also have a background color. A special box, the block, has never any icon and can be used when an icon would be disturbing or misleading. The variety of admonitions and their many typesetting styles are available through a demo.
The following admonition environments are available:
block, warning, notice, question, and summary.
The box is defined by begin and end tags such as !bnotice and !enotice.
The title of the box is fully customizable.
Here are a few examples:
!bwarning
Here is a warning!
!ewarning
!bnotice
This is a notice box with default title.
!enotice
!bnotice Hint
A *Hint* or *Tip* box can use the `notice` box.
!enotice
!bquestion
How many admonition types are there in DocOnce?
!equestion
!bblock This is a block.
A block has never any icon. A block has never any icon,
but may feature a title. It is often used in slides.
!eblock
!bnotice Going deeper
This is text meant to provide more details. The box has the
layout of the notice box, but a custom title, here *Going deeper*.
!enotice
Finally some summary:
!bsummary
The main message is to utilize the admonition styles for
marking different parts of the text
!esummary
The above DocOnce code is in the present format rendered as
notice box.
Finally some summary:
The layout of admonitions depend on the format. In the rst and
sphinx formats one applies the native admonitions, but in sphinx
the automake_sphinx.py script manipulates the HTML file to set a
gray background for all admonitions. In html, latex and
pdflatex there is quite some functionality to control the layout of
admonitions.
The command-line argument --html_admon sets the admonition style
for the html format (see demo):
--html_admon=gray for
icons with gray background and small font,--html_admon=yellow
and --html_admon=apricot are similar,
but the icons and colors are different,--html_admon=colors has quite bright colors
as backgrounds for the different admonitions,--html_admon=lyx
gives a white background and small icons,--html_admon=bootstrap_alert gives the common colored admonition
boxes associated with the Bootstrap HTML styles (only effective
if --html_style=boots*),--html_admon=bootstrap_panel applies the panel construction
in Bootstrap to make admonition boxes with (normally) white background
but a colored background for the title (only effective
if --html_style=boots*),--html_admon=paragraph results in a simple paragraph with the
admon title as heading.--html_admon_bg_color=... and --html_admon_bd_color=...
can be used to override the default background and boundary frame colors
of the admon styles (respectively). These options have only effect
for the apricot, yellow, and gray styles.
Some recommended combinations for admonitions in HTML are
--html_style=bloodish, --html_admon=gray, --pygments_html_style=none or
--pygments_html_style=default--html_style=blueish2, --html_admon=yellow, --pygments_html_style=none or --pygments_html_style=default--html_style=boots*, --html_admon=bootstrap_alert or --html_admon=bootstrap_panel
In latex and pdflatex, the type of admonition style is set by
the command-line option --latex_admon=.
Several values are available (see demo):
paragraph is the simplest type of admonition and typeset
as plain text with an optional paragraph heading.colors1 (inspired by the original NumPy User Guide in LaTeX/PDF)
applies different colors for
the different admons with an embedded icon.colors2 is like colors1 but the text is wrapped around the icon.mdfbox is the default and gives rounded white boxes with a potential
title and no icon (using the very flexible mdframed packaged in LaTeX).graybox2 has square corners, gray background, and is narrower
than mdfbox. One special feature of graybox2 is the summary
admon, which has a different look with horizontal rules only,
and for A4 format, the summary box is half of the text width and
wrapped with running text around (if it does not contain verbatim text,
in that case the standard graybox2 style is used). This small
summary box is effective in proposals to disperse small paragraphs
of key points around.grayicon has icons and a light gray background.yellowicon has icons and a light yellow background.--latex_admon_color=... that can be used
to override the default color. Values are either saturated colors
like gray!10 or an RGB tuple 0.95,0.91,0.97. The chosen color
replaces all default colors for all admon styles except paragraph.
For example, an oval gray box is produced by --latex_admon=mdfbox
and '--latex_admon_color=gray!10' (note the quotes: they are necessary
to avoid a Bash error due to the exclamation mark in the color
specification).
The mdfbox admonition styles has boxes with many possibilities for
customization by editing the .tex file. For example, linecolor
sets the color of the frame border and frametitlebackgroundcolor
sets the background color of the title area. A dark blue frame and
a light blue background for the title is produced by this automatic
edit:
doconce replace 'linecolor=black,' 'linecolor=darkblue,' mydoc.tex
doconce subst 'frametitlebackgroundcolor=.*?,' 'frametitlebackgroundcolor=blue!5 mydoc.tex
Admonition titles without a period, exclamation mark, or colon at the end
will by default get a period at the end. For some LaTeX admonitions
(e.g., mdfbox), it may be natural to view the title with a heading
without any period. The command-line option --latex_admon_title_no_period
avoids appending a period.
Sometimes one sets a special background color in the admonitions, and
colored code blocks, which look fine in the running text, may then
have inappropriate colors inside admonitions. The option
--latex_admon_envir_map=... is used to map an environment (usually
for code) to a new style inside admonitions. Specifying a number,
say 2, as in --latex_admon_envir_map=2, appends the number
to all environments inside admonitions, so !bc pycod becomes
effectively !bc pycod2.
One can then in doconce ptex2tex (or in the ptex2tex configuration
file) specify the typesetting
of the pycod2 environment.
Otherwise the specification must be a mapping for each envir
that should be changed inside the admons:
--latex_admon_envir_map=pycod-pycod_yellow,fpro-fpro2
i.e., a from-to, from-to type of syntax. In this particular example,
the !bc pycod environment becomes !bc pycod_yellow and
!bc fpro becomes !bc fpro2 inside admonitions.
A plain box without any title or colored background, just a rectangular frame, is also available. The syntax goes like
!bbox
!bt
\[ \nabla\cdot\boldsymbol{u} = 0 \quad\hbox{(mass balance)}\]
!et
!ebox
resulting in
Admonitions are usually used to typeset something that should be distinct from the running text: a warning, a remark, a notification, a question, a summary, while a box is often used to highlight a key finding in the running text: an equation, a hypothesis, a theorem, a rule, or a conclusion.
LaTeX writers are often fond of their favorite environments and think that formats like DocOnce, Markdown, and HTML are primitive without these favorite environments. DocOnce, however, offers user-defined environments with begin and end tags, as typical in LaTeX. This section explains how to define such user-defined environments.
Remark. Special environments can always be implemented by Mako code as illustrated in the section Example: Defining a Theorem Environment, but the DocOnce user-defined environments are easier to use.
For example, suppose you want to typeset examples using a native example environment in LaTeX, while other formats can simply typeset examples as subsections. You can then introduce your own example environment in DocOnce and write the environment like this:
!bu-example Addition label=ex:math:1p1
We have
!bt
\[ 1 + 1 = 2 \]
!et
|!eu-example
The convention for this type of examples is to have a title,
and the title line
may feature label=xxx, where we can use xxx as a label for the
example.
The example environment above is in the ${FORMAT} output format
typeset like this:
We have $$ 1 + 1 = 2 $$
The definition of the example environment must be done in a Python
module userdef_environments, located in the same directory as the
DocOnce source code or the parent directory.
In this file (userdef_environments.py),
we must provide a dictionary envir2format for translating an
environment into the right code for a specific format:
envir2format = {
'intro': {
'latex': r"""
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{example}{Example}[section]
""",},
'example': {
'latex': example,
'do': do_example,
},
}
The intro key contains initializing statements for the LaTeX and
HTML formats (the preamble and the head tag, respectively).
Here, we need the amsthm package and a definition of the example
environment in LaTeX. No initialization is needed for HTML.
The other keys are the names of the environments. For each environment,
we use a function to format the code for a specific output format.
The do key is a default DocOnce formatting, expressed in
DocOnce syntax and applied if the output format is not present amont
the other keys. The LaTeX output is here defined by the function
example:
def example(text, titleline, counter, format):
"""LaTeX typesetting of example environment."""
label, titleline = get_label(titleline)
s = r"""
\begin{example}
"""
if label:
s += 'label{%s}\n' % label # no \ (is added by DocOnce)
s += r"""
\noindent\emph{%s}.
%s
\end{example}
""" % (titleline, text)
return s
def get_label(titleline):
label = ''
if 'label=' in titleline:
pattern = r'label=([^\s]+)'
m = re.search(pattern, titleline)
if m:
label = m.group(1)
titleline = re.sub(pattern, '', titleline).strip()
return label, titleline
The arguments are text for the body of the environment, titleline
for the title (everything that comes after !bc-example on the line),
an integer counter that counts the number of the current environment
(1, 2, and so on, which can be used for reference as an alternative to
the label), and the format string holding the user's output format.
In the present case,
we add the label inside the example environment if we have a label
in the title, and we typeset the title in the emphasize font.
Otherwise, we rely on the standard example (or newtheorem)
LaTeX environment.
In HTML and other formats, we simply typeset the example as a subsection:
def do_example(text, titleline, counter, format):
"""General typesetting of example environment via a section."""
label, titleline = get_label(titleline)
s = """
===== Example %d: %s =====
""" % (counter, titleline)
if label:
s += 'label{%s}\n' % label
s += '\n%s\n\n' % text
return s
We quickly encounter a problem when referring to a specific example.
In LaTeX, we want to write Example ref{label}, using the label
defined in the example heading. In other formats, this label is a
section number, or usually the section (example) heading. Different
wording is needed for different formats. This is easiest accomplished
by a little Mako function in the top of the DocOnce source:
<%
def refex(label, capital=False):
if FORMAT in ('latex', 'pdflatex'):
return 'Example ref{%s}' % label
else:
s = 'The ' if capital else 'the '
s += 'example in Section ref{%s}' % label
return s
%>
We can then write something like
${refex('ex:test:1p1', capital=True)} demonstrates how to do 1+1.
That is, the calculation 1+1 appears in ${refex('ex:test:1p1')}.
Note that we distinguish between capital=True, which means that the
example reference opens a sentence, and capital=False, which refers
to a reference later in the sentence. In HTML we see the difference:
The example in the section
<a href="#ex:test:1p1">Example 1: A test function</a>
demonstrates how to do 1+1.
That is, the calculation 1+1 appears in the example in the section
<a href="#ex:test:1p1">Example 1: A test function</a>.
while there is no difference in LaTeX since we refer to Example with capital E anyway:
Example~\ref{ex:test:1p1} demonstrates how to do 1+1.
That is, the calculation 1+1 appears in Example~\ref{ex:test:1p1}.
To summarize, the example environment together with the refex Mako
function allows you to work with native LaTeX example environments, while
there is a neat alternative solution for all other formats.
You may take a look at a complete userdef_environments.py file to see this example environment and another highligh environment where we define blue boxes in LaTeX and HTML and rely on a standard notice admon for all other formats. The highlight environment is written like
!bu-highlight Highlight box!
This environment is used to highlight something:
!bt
\[ E = mc^2 \]
!et
!eu-highlight
and typeset (in ${FORMAT}) as
userdef_environments.py!
Make sure you run the userdef_environments.py file to check
that all syntax is correct:
Terminal> python userdef_environments.py
A common error is to have the envir2format dictionary defined
before the functions it refers to.
A complete example showing how one can create tailored environments
for computer code, using --latex_code_style,
in particular the following one (with a caption),

appears at the end of the document Demonstration of DocOnce support for LaTeX code block environments.
DocOnce applies the software tool Publish to handle the bibliography in a document. With Publish it is easy to import BibTeX data and maintain a database in a clean, self-explanatory textual format. From the Publish format it is easy to go BibTeX and reST or straightforward DocOnce typesetting (and from there to HTML, plain text, wiki formats, and so on).
Installing Publish is trivial: either do
Terminal> pip install -e \
hg+https://bitbucket.org/logg/publish#egg=publish#egg=publish
or checkout the code on bitbucket.org:
Terminal> hg clone https://bitbucket.org/logg/publish
Terminal> cd publish
Terminal> sudo python setup.py install
Many scientists have their bibliographic data in the BibTex format. Here we
assume that you have two files, refs1.bib and refs2.bib. These can
be imported to a Publish database, residing in the file papers.pub,
by the commands
publish import refs1.bib
publish import refs2.bib
During import, Publish may ask you for accepting the name of new
institutions or journals. Publish already have a database of journals
and institutions/departments, but when you add new, you also get
a file venues.list (in the current working directory) which will be used
for future imports in this directory. Make sure you store publish.pub
and venues.list along with your DocOnce document files (they do not
need to reside in the same directory, but make sure you add them to
your version control system).
The utility doconce fix_bibtex4publish file.bib fixes several known
issues with BibTeX files such that Publish has a better chance of
accepting the entries. Run this utility first, then run Publish,
respond to any requirements that Publish spits out, remove papers.pub
if it exists, and run the import statements again.
Although references are visible as numbers only in the output, it is recommended to have apply a nice, consistent typesetting of your keys. It is suggested to use the following scheme:
Langtangen_2003a # single author
Langtangen_Pedersen_2002 # two authors
Langtangen_et_al_2002 # three or more authors
One can add a, b, c, and so forth if several keys feature the same authors and year.
When you get some new BibTeX references you simply put them in
a file, say refs3.pub and run the publish import refs3.pub command
to update the database. You may also consider editing the papers.pub
file directly when adding new references.
Export of everything in the database to BibTeX is done by
publish export mybibtexfile.bib
You can easily export subsets of the database, e.g., only papers associated
with a particular author (the Publish manual has details on how this is
done). DocOnce will automatically export the database to BibTeX if
the output format is latex or pdflatex.
We use the command
cite{key}
to refer to a publication with bibliographic key key.
Here is an example: [3] discussed propagation of
large destructive water waves, [4] gave
an overview of numerical methods for solving the Navier-Stokes equations,
while the use of Backward Kolmogorov equations for analyzing
random vibrations was investigated in [5].
The book chapter [6] contains information on
C++ software tools for programming multigrid methods. A real retro
reference is [7] about a big FORTRAN package.
Multiple references are also possible, e.g., see
[3] [6].
A LaTeX-style cite command with additional detailed reference is also possible,
cite[details]{key}
for example as in [4] (Section 2) or [4] (Equation (4.2)).
In LaTeX, the cite command is directly translated to the
corresponding LaTeX version of the command with a backslash; in reST
and Sphinx the citations becomes links, with the citation keys as
names; in HTML the citations are numbered from 1, 2, and so forth
according to their appearance, and the numbers appear as links; while
in other formats the citations are simply the keys inside square
brackets and the corresponding references are listed in the order they
are cited.
The specification of the Publish database file in the DocOnce document
is done one a line containing BIBFILE: papers.pub (you may give
the database file another name and store it in another directory).
The references will be inserted at the place where this command appears.
Before the command you will often want to have a headline with
"References", "Bibliography", or similar.
Here is an example:
======= References =======
BIBFILE: papers.pub
In LaTeX and pdfLaTeX the papers.pub file is exported to BibTeX format
and included in the document, while in all other formats, suitable
text is produced from the database.
The bibliography style is "plain" in LaTeX output. To change this, just
edit the .p.tex file. For example,
doconce format latex mydoc
doconce replace 'bibliographystyle{plain}' 'bibliographystyle{abbrev}' mydoc.p.tex