Skip to content

publish

miscellaneous · scripts/miscellaneous/publish.m

: publish (file)
: publish (file, format)
: publish (file, options)
: publish (file, name, value, …)
: outfile = publish (…)

Turn a script into a document that shows its code, its text and the output it produces.

The script is split into cells at lines that begin with %%. The comment text that follows such a line is the text of the cell; a first line %% Title gives the title. In the text, lines that begin with ‘* ’ are bullets, *bold*, _italic_ and |mono| are emphasised, <http://address> is a link and <<image.png>> includes an image.

format is "html" (the default) or "latex". The options are given as a structure or as name and value pairs:

format

the output format.

outputDir

the folder for the output, by default html next to the script.

evalCode

run the code and show its output (default true).

showCode

show the code (default true).

catchError

continue after an error and show its message (default true).

codeToEvaluate

code to run instead of the script.

imageFormat, figureSnapMethod, useNewFigure, maxHeight, maxWidth, createThumbnail, stylesheet

accepted; figures are saved as PNG when they can be captured.

All files are written inside the output folder. When showCode is true, the source of the script is kept in the document, between the lines ##### SOURCE BEGIN ##### and ##### SOURCE END #####, where grabcode finds it. When showCode is false that copy is omitted together with the code lines. The result outfile is the full name of the document.