# Generate TeX Snippets

Jump to: navigation, search

Usually Isabelle's document preparation system directly generates PDF files from theory files. Sometimes (e.g., when writing a document in cooperation with people not using Isabelle) it is needed to generate only TeX snippets and include them into a normal TeX document.

The idea is to add a TeX command that marks the parts of a theory file that should be exported. The generated file is then transformed by an easy sed invocation. Afterwards, the snippets can simply be used in the TeX file by calling \Snippet{<snippet_name>}.

To annotate a snippet in an Isabelle theory use

 text {*
\DefineSnippet{half_log_simps}{
@{thm [display] half.simps}
@{thm_style [display] concl Loga.log.psimps}
}%EndSnippet
*}


when referring to existing facts, and

 text_raw {*\DefineSnippet{<snippet_name>}{*}
...
text_raw {*}%EndSnippet*}


when referring to arbitrary parts of a theory file in theory mode and proof mode, respectively (i.e., out- or inside of a proof).

At the beginning of your main TeX file add:

 \newcommand{\DefineSnippet}[2]{%
\expandafter\newcommand\csname snippet--#1\endcsname{%
\begin{quote}
\begin{isabelle}
#2
\end{isabelle}
\end{quote}}}
\newcommand{\Snippet}[1]{\csname snippet--#1\endcsname}

\input{generated/snippets}


Then do the following:

Create a file ROOT containing

 session Snippets = "HOL" +
options [
document = "pdf",
document_output = "generated"]
theories
File
document_files
build


which tells the system to generate files in the subdirectory "generated". Then create a directory "document" containing an executable file "build" with the following content:

 #!/bin/bash
find . -type f -name "*.tex" -exec sed -n '/DefineSnippet/,/EndSnippet/p' {} + > ../snippets.tex
touch ../document.pdf


This script will be run in a subdirectory of "generated", hence the occurrences of ".." to refer to "generated".

In order to generate the snippets run

 isabelle build -d . Snippets


and then compile your TeX sources as usual.

## When using old-style isabelle make

For each theory file File.thy containing snippets add to the Makefile:

 sed -n '/DefineSnippet/,/EndSnippet/p' ./Paper/generated/File.tex > generated/snippets.tex