Self-documenting authoring example

Sebastien Mondet
Using m4…
We will use M4

Detailled examples

Creating a “ToDo” tag

Here is the 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
so, with the command:
m4  -D_output_format="LATEX"  main.brtx | brtx [-html|-latex]
with a TODO, the output generated by brtx, will have a TO-DO

Using command line definitions

Here we have the compilation date: Sun Oct 2 14:40:43 EDT 2011
For that we just passed the source:
Here we have compilation date: {t|_todaydate}
through the command:
m4 -D_todaydate="$(date)" main.brtx > main.brtx.tmp

Citations

Let's say we want to use BibTeX for LaTeX output and that we have a bibliography site (./biblio/<refname>.html or ./biblio.html#<refname>). We define CITATION:
define(CITATION, ifelse(_output_format , HTML,
[{link ./biblio/$1.html|$1}],
{bypass end}\cite{$1}{end}))dnl
so that
CITATION(mondet08bracetax)
will give us:
[{link ./biblio/mondet08bracetax.html|mondet08bracetax}]

Using include

With a simple:
{code verycomplexend}
include(./Makefile)
{verycomplexend}
we obtain:

EXAMPLE_SITE_HTML=main.html main.tex

EXAMPLE_SITE_VIM= Makefile.html main.brtx.html

EXAMPLE_SITE= $(EXAMPLE_SITE_HTML) $(EXAMPLE_SITE_VIM) main.pdf main.tex

all: $(EXAMPLE_SITE)

.PHONY: nopdf

nopdf: $(EXAMPLE_SITE_HTML) $(EXAMPLE_SITE_VIM)

#
# Generate the HTML page from source:
#                         m4              brtx -html       brtx -prospro    
#   source bracetax + M4 ---> pure bracetax  --->    HTML       --->     HTML
#
HEVEA_OR_NOT= hevea || echo NoHeveaFound
main.html: main.brtx
	m4 -D_todaydate="date`" -D_output_format="HTML" main.brtx > main.brtx.tmp
	$(BRTX2HTML) -doc -title "Bracetax Example" -link-css ../$(CSS) \
	    -i main.brtx.tmp -o $@
	rm main.brtx.tmp


#
# Generate the HTML page from source:
#                         m4              brtx -html       brtx -prospro    
#   source bracetax + M4 ---> pure bracetax  --->    HTML       --->     HTML
#
main.tex: main.brtx
	m4 -D_todaydate="`date`" -D_output_format="LATEX" main.brtx > main.brtx.tmp
	brtx -doc -title "Self Documenting Example" -latex  -i main.brtx.tmp -o main.tex
	rm main.brtx.tmp 

#
# A PDF with pdflatex
#
main.pdf: main.tex
	pdflatex main && pdflatex main
	rm main.log main.aux main.out

#
# Using VIM to generate an HTML page from a source code
#
Makefile.html: Makefile
	vim -f -R $< \
		-c "sy on" \
		-c 'colorscheme darkblue' \
		-c TOhtml -c 'w! $@.tmp -c 'qa!' && \
	sed -e 's/<title>.*<\/title>/<title>Makefile<\/title>/' \
		$@.tmp > $@
	rm -f $@.tmp

#
# Using VIM to generate an HTML page from a source code
# (with the provided - incomplete - vim plugin
#
main.brtx.html: main.brtx
	vim -f -R $< \
		-c "sy on" \
		-c 'colorscheme darkblue' \
		-c 'source ../../../tools/bracetax_syntax.vim' \
		-c TOhtml -c 'w! $@.tmp' -c 'qa!' && \
	sed -e 's/<title>.*<\/title>/<title>Example - source<\/title>/' \
		$@.tmp > $@ 
	rm -f $@.tmp