src/Doc/System/Presentation.thy
author wenzelm
Sat Nov 11 14:55:30 2017 +0100 (18 months ago)
changeset 67042 677cab7c2b85
parent 63680 6e1e8b5abbfa
child 67043 848672fcaee5
permissions -rw-r--r--
adapted to changed ROOT syntax (see 13857f49d215);
discontinued pointless option -d: always enabled;
wenzelm@61656
     1
(*:maxLineLen=78:*)
wenzelm@61575
     2
wenzelm@28221
     3
theory Presentation
wenzelm@43564
     4
imports Base
wenzelm@28221
     5
begin
wenzelm@28221
     6
wenzelm@58618
     7
chapter \<open>Presenting theories \label{ch:present}\<close>
wenzelm@28221
     8
wenzelm@61575
     9
text \<open>
wenzelm@61575
    10
  Isabelle provides several ways to present the outcome of formal
wenzelm@61575
    11
  developments, including WWW-based browsable libraries or actual printable
wenzelm@61575
    12
  documents. Presentation is centered around the concept of \<^emph>\<open>sessions\<close>
wenzelm@61575
    13
  (\chref{ch:session}). The global session structure is that of a tree, with
wenzelm@61575
    14
  Isabelle Pure at its root, further object-logics derived (e.g.\ HOLCF from
wenzelm@61575
    15
  HOL, and HOL from Pure), and application sessions further on in the
wenzelm@61575
    16
  hierarchy.
wenzelm@28221
    17
wenzelm@61575
    18
  The tools @{tool_ref mkroot} and @{tool_ref build} provide the primary means
wenzelm@61575
    19
  for managing Isabelle sessions, including proper setup for presentation;
wenzelm@62588
    20
  @{tool build} tells the Isabelle process to run any additional stages
wenzelm@62588
    21
  required for document preparation, notably the @{tool_ref document} and
wenzelm@62588
    22
  @{tool_ref latex}. The complete tool chain for managing batch-mode Isabelle
wenzelm@62588
    23
  sessions is illustrated in \figref{fig:session-tools}.
wenzelm@28221
    24
wenzelm@28221
    25
  \begin{figure}[htbp]
wenzelm@28221
    26
  \begin{center}
wenzelm@28221
    27
  \begin{tabular}{lp{0.6\textwidth}}
wenzelm@28221
    28
wenzelm@48814
    29
      @{tool_ref mkroot} & invoked once by the user to initialize the
wenzelm@61503
    30
      session \<^verbatim>\<open>ROOT\<close> with optional \<^verbatim>\<open>document\<close>
wenzelm@48814
    31
      directory; \\
wenzelm@28221
    32
wenzelm@48814
    33
      @{tool_ref build} & invoked repeatedly by the user to keep
wenzelm@48814
    34
      session output up-to-date (HTML, documents etc.); \\
wenzelm@28221
    35
wenzelm@62588
    36
      @{tool_ref process} & run through @{tool_ref build}; \\
wenzelm@28221
    37
wenzelm@48602
    38
      @{tool_ref document} & run by the Isabelle process if document
wenzelm@48602
    39
      preparation is enabled; \\
wenzelm@28221
    40
wenzelm@48602
    41
      @{tool_ref latex} & universal {\LaTeX} tool wrapper invoked
wenzelm@48602
    42
      multiple times by @{tool_ref document}; also useful for manual
wenzelm@48602
    43
      experiments; \\
wenzelm@28221
    44
wenzelm@28221
    45
  \end{tabular}
wenzelm@28221
    46
  \caption{The tool chain of Isabelle session presentation} \label{fig:session-tools}
wenzelm@28221
    47
  \end{center}
wenzelm@28221
    48
  \end{figure}
wenzelm@58618
    49
\<close>
wenzelm@28221
    50
wenzelm@28221
    51
wenzelm@62013
    52
section \<open>Generating HTML browser information \label{sec:info}\<close>
wenzelm@28221
    53
wenzelm@58618
    54
text \<open>
wenzelm@61575
    55
  As a side-effect of building sessions, Isabelle is able to generate theory
wenzelm@61575
    56
  browsing information, including HTML documents that show the theory sources
wenzelm@61575
    57
  and the relationship with its ancestors and descendants. Besides the HTML
wenzelm@61575
    58
  file that is generated for every theory, Isabelle stores links to all
wenzelm@61575
    59
  theories of a session in an index file. As a second hierarchy, groups of
wenzelm@61575
    60
  sessions are organized as \<^emph>\<open>chapters\<close>, with a separate index. Note that the
wenzelm@61575
    61
  implicit tree structure of the session build hierarchy is \<^emph>\<open>not\<close> relevant
wenzelm@51417
    62
  for the presentation.
wenzelm@28221
    63
wenzelm@61406
    64
  \<^medskip>
wenzelm@62013
    65
  To generate theory browsing information for an existing session, just invoke
wenzelm@62013
    66
  @{tool build} with suitable options:
wenzelm@61407
    67
  @{verbatim [display] \<open>isabelle build -o browser_info -v -c FOL\<close>}
wenzelm@28221
    68
wenzelm@61575
    69
  The presentation output will appear in \<^verbatim>\<open>$ISABELLE_BROWSER_INFO/FOL/FOL\<close> as
wenzelm@61575
    70
  reported by the above verbose invocation of the build process.
wenzelm@28221
    71
wenzelm@63680
    72
  Many Isabelle sessions (such as \<^verbatim>\<open>HOL-Library\<close> in \<^dir>\<open>~~/src/HOL/Library\<close>)
wenzelm@63680
    73
  also provide printable documents in PDF. These are prepared automatically as
wenzelm@63680
    74
  well if enabled like this:
wenzelm@61407
    75
  @{verbatim [display] \<open>isabelle build -o browser_info -o document=pdf -v -c HOL-Library\<close>}
wenzelm@48814
    76
wenzelm@61575
    77
  Enabling both browser info and document preparation simultaneously causes an
wenzelm@61575
    78
  appropriate ``document'' link to be included in the HTML index. Documents
wenzelm@61575
    79
  may be generated independently of browser information as well, see
wenzelm@61575
    80
  \secref{sec:tool-document} for further details.
wenzelm@28221
    81
wenzelm@61406
    82
  \<^bigskip>
wenzelm@61575
    83
  The theory browsing information is stored in a sub-directory directory
wenzelm@61575
    84
  determined by the @{setting_ref ISABELLE_BROWSER_INFO} setting plus a prefix
wenzelm@61575
    85
  corresponding to the session chapter and identifier. In order to present
wenzelm@61575
    86
  Isabelle applications on the web, the corresponding subdirectory from
wenzelm@61575
    87
  @{setting ISABELLE_BROWSER_INFO} can be put on a WWW server.
wenzelm@61575
    88
\<close>
wenzelm@28221
    89
wenzelm@61406
    90
wenzelm@58618
    91
section \<open>Preparing session root directories \label{sec:tool-mkroot}\<close>
wenzelm@28221
    92
wenzelm@61575
    93
text \<open>
wenzelm@61575
    94
  The @{tool_def mkroot} tool configures a given directory as session root,
wenzelm@61575
    95
  with some \<^verbatim>\<open>ROOT\<close> file and optional document source directory. Its usage is:
wenzelm@61407
    96
  @{verbatim [display]
wenzelm@61407
    97
\<open>Usage: isabelle mkroot [OPTIONS] [DIR]
wenzelm@28221
    98
wenzelm@28221
    99
  Options are:
wenzelm@48814
   100
    -n NAME      alternative session name (default: DIR base name)
wenzelm@28221
   101
wenzelm@61407
   102
  Prepare session root DIR (default: current directory).\<close>}
wenzelm@28221
   103
wenzelm@61575
   104
  The results are placed in the given directory \<open>dir\<close>, which refers to the
wenzelm@61575
   105
  current directory by default. The @{tool mkroot} tool is conservative in the
wenzelm@61575
   106
  sense that it does not overwrite existing files or directories. Earlier
wenzelm@61575
   107
  attempts to generate a session root need to be deleted manually.
wenzelm@28221
   108
wenzelm@67042
   109
  The generated session template will be accompanied by a formal document,
wenzelm@67042
   110
  with \<open>DIR\<close>\<^verbatim>\<open>/document/root.tex\<close> as its {\LaTeX} entry point (see also
wenzelm@67042
   111
  \chref{ch:present}).
wenzelm@28221
   112
wenzelm@61575
   113
  Option \<^verbatim>\<open>-n\<close> allows to specify an alternative session name; otherwise the
wenzelm@61575
   114
  base name of the given directory is used.
wenzelm@28221
   115
wenzelm@61406
   116
  \<^medskip>
wenzelm@61575
   117
  The implicit Isabelle settings variable @{setting ISABELLE_LOGIC} specifies
wenzelm@61575
   118
  the parent session, and @{setting ISABELLE_DOCUMENT_FORMAT} the document
wenzelm@61575
   119
  format to be filled filled into the generated \<^verbatim>\<open>ROOT\<close> file.
wenzelm@61503
   120
\<close>
wenzelm@28221
   121
wenzelm@28221
   122
wenzelm@58618
   123
subsubsection \<open>Examples\<close>
wenzelm@28221
   124
wenzelm@61575
   125
text \<open>
wenzelm@67042
   126
  Produce session \<^verbatim>\<open>Test\<close> within a separate directory of the same name:
wenzelm@67042
   127
  @{verbatim [display] \<open>isabelle mkroot Test && isabelle build -D Test\<close>}
wenzelm@28221
   128
wenzelm@61406
   129
  \<^medskip>
wenzelm@61575
   130
  Upgrade the current directory into a session ROOT with document preparation,
wenzelm@61575
   131
  and build it:
wenzelm@67042
   132
  @{verbatim [display] \<open>isabelle mkroot && isabelle build -D .\<close>}
wenzelm@58618
   133
\<close>
wenzelm@28221
   134
wenzelm@28221
   135
wenzelm@61407
   136
section \<open>Preparing Isabelle session documents \label{sec:tool-document}\<close>
wenzelm@28221
   137
wenzelm@61575
   138
text \<open>
wenzelm@61575
   139
  The @{tool_def document} tool prepares logic session documents, processing
wenzelm@61575
   140
  the sources as provided by the user and generated by Isabelle. Its usage is:
wenzelm@61407
   141
  @{verbatim [display]
wenzelm@61407
   142
\<open>Usage: isabelle document [OPTIONS] [DIR]
wenzelm@28221
   143
wenzelm@28221
   144
  Options are:
wenzelm@28221
   145
    -c           cleanup -- be aggressive in removing old stuff
wenzelm@28221
   146
    -n NAME      specify document name (default 'document')
wenzelm@52746
   147
    -o FORMAT    specify output format: pdf (default), dvi
wenzelm@28221
   148
    -t TAGS      specify tagged region markup
wenzelm@28221
   149
wenzelm@28221
   150
  Prepare the theory session document in DIR (default 'document')
wenzelm@61407
   151
  producing the specified output format.\<close>}
wenzelm@61407
   152
wenzelm@48814
   153
  This tool is usually run automatically as part of the Isabelle build
wenzelm@48814
   154
  process, provided document preparation has been enabled via suitable
wenzelm@61575
   155
  options. It may be manually invoked on the generated browser information
wenzelm@61575
   156
  document output as well, e.g.\ in case of errors encountered in the batch
wenzelm@61575
   157
  run.
wenzelm@28221
   158
wenzelm@61406
   159
  \<^medskip>
wenzelm@61575
   160
  The \<^verbatim>\<open>-c\<close> option tells @{tool document} to dispose the document sources
wenzelm@61575
   161
  after successful operation! This is the right thing to do for sources
wenzelm@61575
   162
  generated by an Isabelle process, but take care of your files in manual
wenzelm@61575
   163
  document preparation!
wenzelm@28221
   164
wenzelm@61406
   165
  \<^medskip>
wenzelm@61575
   166
  The \<^verbatim>\<open>-n\<close> and \<^verbatim>\<open>-o\<close> option specify the final output file name and format,
wenzelm@61575
   167
  the default is ``\<^verbatim>\<open>document.dvi\<close>''. Note that the result will appear in the
wenzelm@61575
   168
  parent of the target \<^verbatim>\<open>DIR\<close>.
wenzelm@28221
   169
wenzelm@61406
   170
  \<^medskip>
wenzelm@61575
   171
  The \<^verbatim>\<open>-t\<close> option tells {\LaTeX} how to interpret tagged Isabelle command
wenzelm@61575
   172
  regions. Tags are specified as a comma separated list of modifier/name
wenzelm@61575
   173
  pairs: ``\<^verbatim>\<open>+\<close>\<open>foo\<close>'' (or just ``\<open>foo\<close>'') means to keep, ``\<^verbatim>\<open>-\<close>\<open>foo\<close>'' to
wenzelm@61575
   174
  drop, and ``\<^verbatim>\<open>/\<close>\<open>foo\<close>'' to fold text tagged as \<open>foo\<close>. The builtin default is
wenzelm@61575
   175
  equivalent to the tag specification
wenzelm@61575
   176
  ``\<^verbatim>\<open>+theory,+proof,+ML,+visible,-invisible\<close>''; see also the {\LaTeX} macros
wenzelm@63680
   177
  \<^verbatim>\<open>\isakeeptag\<close>, \<^verbatim>\<open>\isadroptag\<close>, and \<^verbatim>\<open>\isafoldtag\<close>, in
wenzelm@63680
   178
  \<^file>\<open>~~/lib/texinputs/isabelle.sty\<close>.
wenzelm@28221
   179
wenzelm@61406
   180
  \<^medskip>
wenzelm@61575
   181
  Document preparation requires a \<^verbatim>\<open>document\<close> directory within the session
wenzelm@61575
   182
  sources. This directory is supposed to contain all the files needed to
wenzelm@61575
   183
  produce the final document --- apart from the actual theories which are
wenzelm@61575
   184
  generated by Isabelle.
wenzelm@28221
   185
wenzelm@61406
   186
  \<^medskip>
wenzelm@61575
   187
  For most practical purposes, @{tool document} is smart enough to create any
wenzelm@61575
   188
  of the specified output formats, taking \<^verbatim>\<open>root.tex\<close> supplied by the user as
wenzelm@61575
   189
  a starting point. This even includes multiple runs of {\LaTeX} to
wenzelm@61575
   190
  accommodate references and bibliographies (the latter assumes \<^verbatim>\<open>root.bib\<close>
wenzelm@61575
   191
  within the same directory).
wenzelm@28221
   192
wenzelm@61575
   193
  In more complex situations, a separate \<^verbatim>\<open>build\<close> script for the document
wenzelm@61575
   194
  sources may be given. It is invoked with command-line arguments for the
wenzelm@61575
   195
  document format and the document variant name. The script needs to produce
wenzelm@61575
   196
  corresponding output files, e.g.\ \<^verbatim>\<open>root.pdf\<close> for target format \<^verbatim>\<open>pdf\<close> (and
wenzelm@61575
   197
  default variants). The main work can be again delegated to @{tool latex},
wenzelm@61575
   198
  but it is also possible to harvest generated {\LaTeX} sources and copy them
wenzelm@61575
   199
  elsewhere.
wenzelm@28221
   200
wenzelm@61406
   201
  \<^medskip>
wenzelm@61575
   202
  When running the session, Isabelle copies the content of the original
wenzelm@61575
   203
  \<^verbatim>\<open>document\<close> directory into its proper place within @{setting
wenzelm@61575
   204
  ISABELLE_BROWSER_INFO}, according to the session path and document variant.
wenzelm@61575
   205
  Then, for any processed theory \<open>A\<close> some {\LaTeX} source is generated and put
wenzelm@61575
   206
  there as \<open>A\<close>\<^verbatim>\<open>.tex\<close>. Furthermore, a list of all generated theory files is
wenzelm@61575
   207
  put into \<^verbatim>\<open>session.tex\<close>. Typically, the root {\LaTeX} file provided by the
wenzelm@61575
   208
  user would include \<^verbatim>\<open>session.tex\<close> to get a document containing all the
wenzelm@61575
   209
  theories.
wenzelm@28221
   210
wenzelm@63680
   211
  The {\LaTeX} versions of the theories require some macros defined in
wenzelm@63680
   212
  \<^file>\<open>~~/lib/texinputs/isabelle.sty\<close>. Doing \<^verbatim>\<open>\usepackage{isabelle}\<close> in
wenzelm@61575
   213
  \<^verbatim>\<open>root.tex\<close> should be fine; the underlying @{tool latex} already includes an
wenzelm@61575
   214
  appropriate path specification for {\TeX} inputs.
wenzelm@28221
   215
wenzelm@61575
   216
  If the text contains any references to Isabelle symbols (such as \<^verbatim>\<open>\<forall>\<close>) then
wenzelm@61575
   217
  \<^verbatim>\<open>isabellesym.sty\<close> should be included as well. This package contains a
wenzelm@61575
   218
  standard set of {\LaTeX} macro definitions \<^verbatim>\<open>\isasym\<close>\<open>foo\<close> corresponding to
wenzelm@61575
   219
  \<^verbatim>\<open>\\<close>\<^verbatim>\<open><\<close>\<open>foo\<close>\<^verbatim>\<open>>\<close>, see @{cite "isabelle-implementation"} for a complete list
wenzelm@61575
   220
  of predefined Isabelle symbols. Users may invent further symbols as well,
wenzelm@63680
   221
  just by providing {\LaTeX} macros in a similar fashion as in
wenzelm@63680
   222
  \<^file>\<open>~~/lib/texinputs/isabellesym.sty\<close> of the Isabelle distribution.
wenzelm@28221
   223
wenzelm@61575
   224
  For proper setup of DVI and PDF documents (with hyperlinks and bookmarks),
wenzelm@63680
   225
  we recommend to include \<^file>\<open>~~/lib/texinputs/pdfsetup.sty\<close> as well.
wenzelm@28221
   226
wenzelm@61406
   227
  \<^medskip>
wenzelm@61575
   228
  As a final step of Isabelle document preparation, @{tool document}~\<^verbatim>\<open>-c\<close> is
wenzelm@61575
   229
  run on the resulting copy of the \<^verbatim>\<open>document\<close> directory. Thus the actual
wenzelm@61575
   230
  output document is built and installed in its proper place. The generated
wenzelm@61575
   231
  sources are deleted after successful run of {\LaTeX} and friends.
wenzelm@48814
   232
wenzelm@48814
   233
  Some care is needed if the document output location is configured
wenzelm@48814
   234
  differently, say within a directory whose content is still required
wenzelm@48814
   235
  afterwards!
wenzelm@58618
   236
\<close>
wenzelm@28221
   237
wenzelm@28221
   238
wenzelm@58618
   239
section \<open>Running {\LaTeX} within the Isabelle environment
wenzelm@58618
   240
  \label{sec:tool-latex}\<close>
wenzelm@28221
   241
wenzelm@61575
   242
text \<open>
wenzelm@61575
   243
  The @{tool_def latex} tool provides the basic interface for Isabelle
wenzelm@61575
   244
  document preparation. Its usage is:
wenzelm@61407
   245
  @{verbatim [display]
wenzelm@61407
   246
\<open>Usage: isabelle latex [OPTIONS] [FILE]
wenzelm@28221
   247
wenzelm@28221
   248
  Options are:
wenzelm@52746
   249
    -o FORMAT    specify output format: pdf (default), dvi,
wenzelm@52746
   250
                 bbl, idx, sty, syms
wenzelm@28221
   251
wenzelm@28221
   252
  Run LaTeX (and related tools) on FILE (default root.tex),
wenzelm@61407
   253
  producing the specified output format.\<close>}
wenzelm@28221
   254
wenzelm@61575
   255
  Appropriate {\LaTeX}-related programs are run on the input file, according
wenzelm@61575
   256
  to the given output format: @{executable latex}, @{executable pdflatex},
wenzelm@61575
   257
  @{executable dvips}, @{executable bibtex} (for \<^verbatim>\<open>bbl\<close>), and @{executable
wenzelm@61575
   258
  makeindex} (for \<^verbatim>\<open>idx\<close>). The actual commands are determined from the
wenzelm@61575
   259
  settings environment (@{setting ISABELLE_PDFLATEX} etc.).
wenzelm@28221
   260
wenzelm@61575
   261
  The \<^verbatim>\<open>sty\<close> output format causes the Isabelle style files to be updated from
wenzelm@61575
   262
  the distribution. This is useful in special situations where the document
wenzelm@61575
   263
  sources are to be processed another time by separate tools.
wenzelm@28221
   264
wenzelm@61575
   265
  The \<^verbatim>\<open>syms\<close> output is for internal use; it generates lists of symbols that
wenzelm@61575
   266
  are available without loading additional {\LaTeX} packages.
wenzelm@58618
   267
\<close>
wenzelm@28221
   268
wenzelm@28221
   269
wenzelm@58618
   270
subsubsection \<open>Examples\<close>
wenzelm@28221
   271
wenzelm@61575
   272
text \<open>
wenzelm@61575
   273
  Invoking @{tool latex} by hand may be occasionally useful when debugging
wenzelm@61575
   274
  failed attempts of the automatic document preparation stage of batch-mode
wenzelm@61575
   275
  Isabelle. The abortive process leaves the sources at a certain place within
wenzelm@61575
   276
  @{setting ISABELLE_BROWSER_INFO}, see the runtime error message for details.
wenzelm@61575
   277
  This enables users to inspect {\LaTeX} runs in further detail, e.g.\ like
wenzelm@61575
   278
  this:
wenzelm@48602
   279
wenzelm@61407
   280
  @{verbatim [display]
wenzelm@61407
   281
\<open>cd "$(isabelle getenv -b ISABELLE_BROWSER_INFO)/Unsorted/Test/document"
wenzelm@61407
   282
isabelle latex -o pdf\<close>}
wenzelm@58618
   283
\<close>
wenzelm@28221
   284
wenzelm@28221
   285
end