doc-src/IsarRef/Thy/Document_Preparation.thy
changeset 27043 3ff111ed85a1
child 27049 5072d6c77baa
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/doc-src/IsarRef/Thy/Document_Preparation.thy	Mon Jun 02 22:50:54 2008 +0200
     1.3 @@ -0,0 +1,427 @@
     1.4 +(* $Id$ *)
     1.5 +
     1.6 +theory Document_Preparation
     1.7 +imports Main
     1.8 +begin
     1.9 +
    1.10 +chapter {* Document preparation \label{ch:document-prep} *}
    1.11 +
    1.12 +text {*
    1.13 +  Isabelle/Isar provides a simple document preparation system based on
    1.14 +  existing {PDF-\LaTeX} technology, with full support of hyper-links
    1.15 +  (both local references and URLs) and bookmarks.  Thus the results
    1.16 +  are equally well suited for WWW browsing and as printed copies.
    1.17 +
    1.18 +  \medskip Isabelle generates {\LaTeX} output as part of the run of a
    1.19 +  \emph{logic session} (see also \cite{isabelle-sys}).  Getting
    1.20 +  started with a working configuration for common situations is quite
    1.21 +  easy by using the Isabelle @{verbatim mkdir} and @{verbatim make}
    1.22 +  tools.  First invoke
    1.23 +\begin{ttbox}
    1.24 +  isatool mkdir Foo
    1.25 +\end{ttbox}
    1.26 +  to initialize a separate directory for session @{verbatim Foo} ---
    1.27 +  it is safe to experiment, since @{verbatim "isatool mkdir"} never
    1.28 +  overwrites existing files.  Ensure that @{verbatim "Foo/ROOT.ML"}
    1.29 +  holds ML commands to load all theories required for this session;
    1.30 +  furthermore @{verbatim "Foo/document/root.tex"} should include any
    1.31 +  special {\LaTeX} macro packages required for your document (the
    1.32 +  default is usually sufficient as a start).
    1.33 +
    1.34 +  The session is controlled by a separate @{verbatim IsaMakefile}
    1.35 +  (with crude source dependencies by default).  This file is located
    1.36 +  one level up from the @{verbatim Foo} directory location.  Now
    1.37 +  invoke
    1.38 +\begin{ttbox}
    1.39 +  isatool make Foo
    1.40 +\end{ttbox}
    1.41 +  to run the @{verbatim Foo} session, with browser information and
    1.42 +  document preparation enabled.  Unless any errors are reported by
    1.43 +  Isabelle or {\LaTeX}, the output will appear inside the directory
    1.44 +  @{verbatim ISABELLE_BROWSER_INFO}, as reported by the batch job in
    1.45 +  verbose mode.
    1.46 +
    1.47 +  \medskip You may also consider to tune the @{verbatim usedir}
    1.48 +  options in @{verbatim IsaMakefile}, for example to change the output
    1.49 +  format from @{verbatim pdf} to @{verbatim dvi}, or activate the
    1.50 +  @{verbatim "-D"} option to retain a second copy of the generated
    1.51 +  {\LaTeX} sources.
    1.52 +
    1.53 +  \medskip See \emph{The Isabelle System Manual} \cite{isabelle-sys}
    1.54 +  for further details on Isabelle logic sessions and theory
    1.55 +  presentation.  The Isabelle/HOL tutorial \cite{isabelle-hol-book}
    1.56 +  also covers theory presentation issues.
    1.57 +*}
    1.58 +
    1.59 +
    1.60 +section {* Markup commands \label{sec:markup} *}
    1.61 +
    1.62 +text {*
    1.63 +  \begin{matharray}{rcl}
    1.64 +    @{command_def "chapter"} & : & \isarkeep{local{\dsh}theory} \\
    1.65 +    @{command_def "section"} & : & \isarkeep{local{\dsh}theory} \\
    1.66 +    @{command_def "subsection"} & : & \isarkeep{local{\dsh}theory} \\
    1.67 +    @{command_def "subsubsection"} & : & \isarkeep{local{\dsh}theory} \\
    1.68 +    @{command_def "text"} & : & \isarkeep{local{\dsh}theory} \\
    1.69 +    @{command_def "text_raw"} & : & \isarkeep{local{\dsh}theory} \\[0.5ex]
    1.70 +    @{command_def "sect"} & : & \isartrans{proof}{proof} \\
    1.71 +    @{command_def "subsect"} & : & \isartrans{proof}{proof} \\
    1.72 +    @{command_def "subsubsect"} & : & \isartrans{proof}{proof} \\
    1.73 +    @{command_def "txt"} & : & \isartrans{proof}{proof} \\
    1.74 +    @{command_def "txt_raw"} & : & \isartrans{proof}{proof} \\
    1.75 +  \end{matharray}
    1.76 +
    1.77 +  Apart from formal comments (see \secref{sec:comments}), markup
    1.78 +  commands provide a structured way to insert text into the document
    1.79 +  generated from a theory (see \cite{isabelle-sys} for more
    1.80 +  information on Isabelle's document preparation tools).
    1.81 +
    1.82 +  \begin{rail}
    1.83 +    ('chapter' | 'section' | 'subsection' | 'subsubsection' | 'text') target? text
    1.84 +    ;
    1.85 +    ('text\_raw' | 'sect' | 'subsect' | 'subsubsect' | 'txt' | 'txt\_raw') text
    1.86 +    ;
    1.87 +  \end{rail}
    1.88 +
    1.89 +  \begin{descr}
    1.90 +
    1.91 +  \item [@{command "chapter"}, @{command "section"}, @{command
    1.92 +  "subsection"}, and @{command "subsubsection"}] mark chapter and
    1.93 +  section headings.
    1.94 +
    1.95 +  \item [@{command "text"} and @{command "txt"}] specify paragraphs of
    1.96 +  plain text.
    1.97 +
    1.98 +  \item [@{command "text_raw"} and @{command "txt_raw"}] insert
    1.99 +  {\LaTeX} source into the output, without additional markup.  Thus
   1.100 +  the full range of document manipulations becomes available.
   1.101 +
   1.102 +  \end{descr}
   1.103 +
   1.104 +  The @{text "text"} argument of these markup commands (except for
   1.105 +  @{command "text_raw"}) may contain references to formal entities
   1.106 +  (``antiquotations'', see also \secref{sec:antiq}).  These are
   1.107 +  interpreted in the present theory context, or the named @{text
   1.108 +  "target"}.
   1.109 +
   1.110 +  Any of these markup elements corresponds to a {\LaTeX} command with
   1.111 +  the name prefixed by @{verbatim "\\isamarkup"}.  For the sectioning
   1.112 +  commands this is a plain macro with a single argument, e.g.\
   1.113 +  @{verbatim "\\isamarkupchapter{"}@{text "\<dots>"}@{verbatim "}"} for
   1.114 +  @{command "chapter"}.  The @{command "text"} markup results in a
   1.115 +  {\LaTeX} environment @{verbatim "\\begin{isamarkuptext}"} @{text
   1.116 +  "\<dots>"} @{verbatim "\\end{isamarkuptext}"}, while @{command "text_raw"}
   1.117 +  causes the text to be inserted directly into the {\LaTeX} source.
   1.118 +
   1.119 +  \medskip The proof markup commands closely resemble those for theory
   1.120 +  specifications, but have a different formal status and produce
   1.121 +  different {\LaTeX} macros.  Also note that the @{command_ref
   1.122 +  "header"} declaration (see \secref{sec:begin-thy}) admits to insert
   1.123 +  section markup just preceding the actual theory definition.
   1.124 +*}
   1.125 +
   1.126 +
   1.127 +section {* Antiquotations \label{sec:antiq} *}
   1.128 +
   1.129 +text {*
   1.130 +  \begin{matharray}{rcl}
   1.131 +    @{antiquotation_def "theory"} & : & \isarantiq \\
   1.132 +    @{antiquotation_def "thm"} & : & \isarantiq \\
   1.133 +    @{antiquotation_def "prop"} & : & \isarantiq \\
   1.134 +    @{antiquotation_def "term"} & : & \isarantiq \\
   1.135 +    @{antiquotation_def const} & : & \isarantiq \\
   1.136 +    @{antiquotation_def abbrev} & : & \isarantiq \\
   1.137 +    @{antiquotation_def typeof} & : & \isarantiq \\
   1.138 +    @{antiquotation_def typ} & : & \isarantiq \\
   1.139 +    @{antiquotation_def thm_style} & : & \isarantiq \\
   1.140 +    @{antiquotation_def term_style} & : & \isarantiq \\
   1.141 +    @{antiquotation_def "text"} & : & \isarantiq \\
   1.142 +    @{antiquotation_def goals} & : & \isarantiq \\
   1.143 +    @{antiquotation_def subgoals} & : & \isarantiq \\
   1.144 +    @{antiquotation_def prf} & : & \isarantiq \\
   1.145 +    @{antiquotation_def full_prf} & : & \isarantiq \\
   1.146 +    @{antiquotation_def ML} & : & \isarantiq \\
   1.147 +    @{antiquotation_def ML_type} & : & \isarantiq \\
   1.148 +    @{antiquotation_def ML_struct} & : & \isarantiq \\
   1.149 +  \end{matharray}
   1.150 +
   1.151 +  The text body of formal comments (see also \secref{sec:comments})
   1.152 +  may contain antiquotations of logical entities, such as theorems,
   1.153 +  terms and types, which are to be presented in the final output
   1.154 +  produced by the Isabelle document preparation system (see also
   1.155 +  \chref{ch:document-prep}).
   1.156 +
   1.157 +  Thus embedding of ``@{text "@{term [show_types] \"f x = a + x\"}"}''
   1.158 +  within a text block would cause
   1.159 +  \isa{{\isacharparenleft}f{\isasymColon}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isacharparenright}\ {\isacharparenleft}x{\isasymColon}{\isacharprime}a{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}a{\isasymColon}{\isacharprime}a{\isacharparenright}\ {\isacharplus}\ x} to appear in the final {\LaTeX} document.  Also note that theorem
   1.160 +  antiquotations may involve attributes as well.  For example,
   1.161 +  @{text "@{thm sym [no_vars]}"} would print the theorem's
   1.162 +  statement where all schematic variables have been replaced by fixed
   1.163 +  ones, which are easier to read.
   1.164 +
   1.165 +  \begin{rail}
   1.166 +    atsign lbrace antiquotation rbrace
   1.167 +    ;
   1.168 +
   1.169 +    antiquotation:
   1.170 +      'theory' options name |
   1.171 +      'thm' options thmrefs |
   1.172 +      'prop' options prop |
   1.173 +      'term' options term |
   1.174 +      'const' options term |
   1.175 +      'abbrev' options term |
   1.176 +      'typeof' options term |
   1.177 +      'typ' options type |
   1.178 +      'thm\_style' options name thmref |
   1.179 +      'term\_style' options name term |
   1.180 +      'text' options name |
   1.181 +      'goals' options |
   1.182 +      'subgoals' options |
   1.183 +      'prf' options thmrefs |
   1.184 +      'full\_prf' options thmrefs |
   1.185 +      'ML' options name |
   1.186 +      'ML\_type' options name |
   1.187 +      'ML\_struct' options name
   1.188 +    ;
   1.189 +    options: '[' (option * ',') ']'
   1.190 +    ;
   1.191 +    option: name | name '=' name
   1.192 +    ;
   1.193 +  \end{rail}
   1.194 +
   1.195 +  Note that the syntax of antiquotations may \emph{not} include source
   1.196 +  comments @{verbatim "(*"}~@{text "\<dots>"}~@{verbatim "*)"} or verbatim
   1.197 +  text @{verbatim "{"}@{verbatim "*"}~@{text "\<dots>"}~@{verbatim
   1.198 +  "*"}@{verbatim "}"}.
   1.199 +
   1.200 +  \begin{descr}
   1.201 +  
   1.202 +  \item [@{text "@{theory A}"}] prints the name @{text "A"}, which is
   1.203 +  guaranteed to refer to a valid ancestor theory in the current
   1.204 +  context.
   1.205 +
   1.206 +  \item [@{text "@{thm a\<^sub>1 \<dots> a\<^sub>n}"}] prints theorems
   1.207 +  @{text "a\<^sub>1 \<dots> a\<^sub>n"}.  Note that attribute specifications
   1.208 +  may be included as well (see also \secref{sec:syn-att}); the
   1.209 +  @{attribute_ref no_vars} rule (see \secref{sec:misc-meth-att}) would
   1.210 +  be particularly useful to suppress printing of schematic variables.
   1.211 +
   1.212 +  \item [@{text "@{prop \<phi>}"}] prints a well-typed proposition @{text
   1.213 +  "\<phi>"}.
   1.214 +
   1.215 +  \item [@{text "@{term t}"}] prints a well-typed term @{text "t"}.
   1.216 +
   1.217 +  \item [@{text "@{const c}"}] prints a logical or syntactic constant
   1.218 +  @{text "c"}.
   1.219 +  
   1.220 +  \item [@{text "@{abbrev c x\<^sub>1 \<dots> x\<^sub>n}"}] prints a constant
   1.221 +  abbreviation @{text "c x\<^sub>1 \<dots> x\<^sub>n \<equiv> rhs"} as defined in
   1.222 +  the current context.
   1.223 +
   1.224 +  \item [@{text "@{typeof t}"}] prints the type of a well-typed term
   1.225 +  @{text "t"}.
   1.226 +
   1.227 +  \item [@{text "@{typ \<tau>}"}] prints a well-formed type @{text "\<tau>"}.
   1.228 +  
   1.229 +  \item [@{text "@{thm_style s a}"}] prints theorem @{text a},
   1.230 +  previously applying a style @{text s} to it (see below).
   1.231 +  
   1.232 +  \item [@{text "@{term_style s t}"}] prints a well-typed term @{text
   1.233 +  t} after applying a style @{text s} to it (see below).
   1.234 +
   1.235 +  \item [@{text "@{text s}"}] prints uninterpreted source text @{text
   1.236 +  s}.  This is particularly useful to print portions of text according
   1.237 +  to the Isabelle {\LaTeX} output style, without demanding
   1.238 +  well-formedness (e.g.\ small pieces of terms that should not be
   1.239 +  parsed or type-checked yet).
   1.240 +
   1.241 +  \item [@{text "@{goals}"}] prints the current \emph{dynamic} goal
   1.242 +  state.  This is mainly for support of tactic-emulation scripts
   1.243 +  within Isar --- presentation of goal states does not conform to
   1.244 +  actual human-readable proof documents.
   1.245 +
   1.246 +  Please do not include goal states into document output unless you
   1.247 +  really know what you are doing!
   1.248 +  
   1.249 +  \item [@{text "@{subgoals}"}] is similar to @{text "@{goals}"}, but
   1.250 +  does not print the main goal.
   1.251 +  
   1.252 +  \item [@{text "@{prf a\<^sub>1 \<dots> a\<^sub>n}"}] prints the (compact)
   1.253 +  proof terms corresponding to the theorems @{text "a\<^sub>1 \<dots>
   1.254 +  a\<^sub>n"}. Note that this requires proof terms to be switched on
   1.255 +  for the current object logic (see the ``Proof terms'' section of the
   1.256 +  Isabelle reference manual for information on how to do this).
   1.257 +  
   1.258 +  \item [@{text "@{full_prf a\<^sub>1 \<dots> a\<^sub>n}"}] is like @{text
   1.259 +  "@{prf a\<^sub>1 \<dots> a\<^sub>n}"}, but displays the full proof terms,
   1.260 +  i.e.\ also displays information omitted in the compact proof term,
   1.261 +  which is denoted by ``@{text _}'' placeholders there.
   1.262 +  
   1.263 +  \item [@{text "@{ML s}"}, @{text "@{ML_type s}"}, and @{text
   1.264 +  "@{ML_struct s}"}] check text @{text s} as ML value, type, and
   1.265 +  structure, respectively.  The source is displayed verbatim.
   1.266 +
   1.267 +  \end{descr}
   1.268 +
   1.269 +  \medskip The following standard styles for use with @{text
   1.270 +  thm_style} and @{text term_style} are available:
   1.271 +
   1.272 +  \begin{descr}
   1.273 +  
   1.274 +  \item [@{text lhs}] extracts the first argument of any application
   1.275 +  form with at least two arguments -- typically meta-level or
   1.276 +  object-level equality, or any other binary relation.
   1.277 +  
   1.278 +  \item [@{text rhs}] is like @{text lhs}, but extracts the second
   1.279 +  argument.
   1.280 +  
   1.281 +  \item [@{text "concl"}] extracts the conclusion @{text C} from a rule
   1.282 +  in Horn-clause normal form @{text "A\<^sub>1 \<Longrightarrow> \<dots> A\<^sub>n \<Longrightarrow> C"}.
   1.283 +  
   1.284 +  \item [@{text "prem1"}, \dots, @{text "prem9"}] extract premise
   1.285 +  number @{text "1, \<dots>, 9"}, respectively, from from a rule in
   1.286 +  Horn-clause normal form @{text "A\<^sub>1 \<Longrightarrow> \<dots> A\<^sub>n \<Longrightarrow> C"}
   1.287 +
   1.288 +  \end{descr}
   1.289 +
   1.290 +  \medskip
   1.291 +  The following options are available to tune the output.  Note that most of
   1.292 +  these coincide with ML flags of the same names (see also \cite{isabelle-ref}).
   1.293 +
   1.294 +  \begin{descr}
   1.295 +
   1.296 +  \item[@{text "show_types = bool"} and @{text "show_sorts = bool"}]
   1.297 +  control printing of explicit type and sort constraints.
   1.298 +
   1.299 +  \item[@{text "show_structs = bool"}] controls printing of implicit
   1.300 +  structures.
   1.301 +
   1.302 +  \item[@{text "long_names = bool"}] forces names of types and
   1.303 +  constants etc.\ to be printed in their fully qualified internal
   1.304 +  form.
   1.305 +
   1.306 +  \item[@{text "short_names = bool"}] forces names of types and
   1.307 +  constants etc.\ to be printed unqualified.  Note that internalizing
   1.308 +  the output again in the current context may well yield a different
   1.309 +  result.
   1.310 +
   1.311 +  \item[@{text "unique_names = bool"}] determines whether the printed
   1.312 +  version of qualified names should be made sufficiently long to avoid
   1.313 +  overlap with names declared further back.  Set to @{text false} for
   1.314 +  more concise output.
   1.315 +
   1.316 +  \item[@{text "eta_contract = bool"}] prints terms in @{text
   1.317 +  \<eta>}-contracted form.
   1.318 +
   1.319 +  \item[@{text "display = bool"}] indicates if the text is to be
   1.320 +  output as multi-line ``display material'', rather than a small piece
   1.321 +  of text without line breaks (which is the default).
   1.322 +
   1.323 +  \item[@{text "break = bool"}] controls line breaks in non-display
   1.324 +  material.
   1.325 +
   1.326 +  \item[@{text "quotes = bool"}] indicates if the output should be
   1.327 +  enclosed in double quotes.
   1.328 +
   1.329 +  \item[@{text "mode = name"}] adds @{text name} to the print mode to
   1.330 +  be used for presentation (see also \cite{isabelle-ref}).  Note that
   1.331 +  the standard setup for {\LaTeX} output is already present by
   1.332 +  default, including the modes @{text latex} and @{text xsymbols}.
   1.333 +
   1.334 +  \item[@{text "margin = nat"} and @{text "indent = nat"}] change the
   1.335 +  margin or indentation for pretty printing of display material.
   1.336 +
   1.337 +  \item[@{text "source = bool"}] prints the source text of the
   1.338 +  antiquotation arguments, rather than the actual value.  Note that
   1.339 +  this does not affect well-formedness checks of @{antiquotation
   1.340 +  "thm"}, @{antiquotation "term"}, etc. (only the @{antiquotation
   1.341 +  "text"} antiquotation admits arbitrary output).
   1.342 +
   1.343 +  \item[@{text "goals_limit = nat"}] determines the maximum number of
   1.344 +  goals to be printed.
   1.345 +
   1.346 +  \item[@{text "locale = name"}] specifies an alternative locale
   1.347 +  context used for evaluating and printing the subsequent argument.
   1.348 +
   1.349 +  \end{descr}
   1.350 +
   1.351 +  For boolean flags, ``@{text "name = true"}'' may be abbreviated as
   1.352 +  ``@{text name}''.  All of the above flags are disabled by default,
   1.353 +  unless changed from ML.
   1.354 +
   1.355 +  \medskip Note that antiquotations do not only spare the author from
   1.356 +  tedious typing of logical entities, but also achieve some degree of
   1.357 +  consistency-checking of informal explanations with formal
   1.358 +  developments: well-formedness of terms and types with respect to the
   1.359 +  current theory or proof context is ensured here.
   1.360 +*}
   1.361 +
   1.362 +
   1.363 +section {* Tagged commands \label{sec:tags} *}
   1.364 +
   1.365 +text {*
   1.366 +  Each Isabelle/Isar command may be decorated by presentation tags:
   1.367 +
   1.368 +  \indexouternonterm{tags}
   1.369 +  \begin{rail}
   1.370 +    tags: ( tag * )
   1.371 +    ;
   1.372 +    tag: '\%' (ident | string)
   1.373 +  \end{rail}
   1.374 +
   1.375 +  The tags @{text "theory"}, @{text "proof"}, @{text "ML"} are already
   1.376 +  pre-declared for certain classes of commands:
   1.377 +
   1.378 + \medskip
   1.379 +
   1.380 +  \begin{tabular}{ll}
   1.381 +    @{text "theory"} & theory begin/end \\
   1.382 +    @{text "proof"} & all proof commands \\
   1.383 +    @{text "ML"} & all commands involving ML code \\
   1.384 +  \end{tabular}
   1.385 +
   1.386 +  \medskip The Isabelle document preparation system (see also
   1.387 +  \cite{isabelle-sys}) allows tagged command regions to be presented
   1.388 +  specifically, e.g.\ to fold proof texts, or drop parts of the text
   1.389 +  completely.
   1.390 +
   1.391 +  For example ``@{command "by"}~@{text "%invisible auto"}'' would
   1.392 +  cause that piece of proof to be treated as @{text invisible} instead
   1.393 +  of @{text "proof"} (the default), which may be either show or hidden
   1.394 +  depending on the document setup.  In contrast, ``@{command
   1.395 +  "by"}~@{text "%visible auto"}'' would force this text to be shown
   1.396 +  invariably.
   1.397 +
   1.398 +  Explicit tag specifications within a proof apply to all subsequent
   1.399 +  commands of the same level of nesting.  For example, ``@{command
   1.400 +  "proof"}~@{text "%visible \<dots>"}~@{command "qed"}'' would force the
   1.401 +  whole sub-proof to be typeset as @{text visible} (unless some of its
   1.402 +  parts are tagged differently).
   1.403 +*}
   1.404 +
   1.405 +
   1.406 +section {* Draft presentation *}
   1.407 +
   1.408 +text {*
   1.409 +  \begin{matharray}{rcl}
   1.410 +    @{command_def "display_drafts"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
   1.411 +    @{command_def "print_drafts"}@{text "\<^sup>*"} & : & \isarkeep{\cdot} \\
   1.412 +  \end{matharray}
   1.413 +
   1.414 +  \begin{rail}
   1.415 +    ('display\_drafts' | 'print\_drafts') (name +)
   1.416 +    ;
   1.417 +  \end{rail}
   1.418 +
   1.419 +  \begin{descr}
   1.420 +
   1.421 +  \item [@{command "display_drafts"}~@{text paths} and @{command
   1.422 +  "print_drafts"}~@{text paths}] perform simple output of a given list
   1.423 +  of raw source files.  Only those symbols that do not require
   1.424 +  additional {\LaTeX} packages are displayed properly, everything else
   1.425 +  is left verbatim.
   1.426 +
   1.427 +  \end{descr}
   1.428 +*}
   1.429 +
   1.430 +end