{header|
{title|Self-documenting authoring example}
{authors|Sebastien Mondet}
{subtitle|Using m4{...}}
}
{section 1 sec_links|Some links}
We will use {link http://en.wikipedia.org/wiki/M4_(computer_language)|M4}
{section 1 sec_examples|Detailled examples}
{section 2 sec_def_todo|Creating a {q|ToDo} tag}
define(`TODO', ifelse(_output_format , HTML ,
`{bypass end}<span style="color: red; background-color: yellow">TO-DO</span>{end}',
`{bypass end}\textcolor{red}{TO-DO}{end}'))dnl
Here is the M4 code:
{code e m4_code}
`define'(`TODO', `ifelse'(`_output_format', HTML ,
`{bypass end}<span style="color: red; background-color: yellow">TO-DO</span>{end}',
`{bypass end}\textcolor{red}{TO-DO}{end}'))`dnl'
{e}
so, with the command:
{code e shell_code}
m4 -D_output_format="LATEX" main.brtx | brtx [-html|-latex]
{e}
with a {t|`TODO'}, the output generated by {t|brtx}, will have a TODO
{section 2 sec_date_command|Using command line definitions}
Here we have the compilation date: {t|_todaydate}
{p}
For that we just passed the source:
{code e brtx_code}
Here we have compilation date: {t|`_todaydate'}
{e}
through the command:
{code e shell_code}
m4 -D`_todaydate'="$(date)" main.brtx > main.brtx.tmp
{e}
{section 2 sec_biblio|Citations}
Let's say we want to use BibTeX for LaTeX output and that we have a
bibliography site ({t|./biblio/<refname>.html} or
{t|./biblio.html{#}<refname>}).
define(`CITATION', ifelse(_output_format , HTML ,
`[{link ./biblio/$1.html|$1}]',
`{bypass end}\cite{$1}{end}'))dnl
We define `CITATION':
{code eee}
`define'(`CITATION', `ifelse'(`_output_format' , HTML,
[{link ./biblio/$1.html|$1}],
`{bypass end}\cite{$1}{end}'))`dnl'
{eee}
so that
{code eee}
`CITATION'(mondet08bracetax)
{eee}
will give us:
{code eee}
CITATION(mondet08bracetax)
{eee}
{section 2 sec_include|Using {t|include}}
With a simple:
{code e brtx_code}
{code verycomplexend}
`include'(./Makefile)
{verycomplexend}
{e}
we obtain:
{code verycomplexend}
include(./Makefile)
{verycomplexend}