doc-src/TutorialI/Documents/Documents.thy
author wenzelm
Wed, 09 Jan 2002 14:01:09 +0100
changeset 12681 84188d1574ee
parent 12674 106d62d106fc
child 12683 99c662efd2fd
permissions -rw-r--r--
tuned;
     1 (*<*)
     2 theory Documents = Main:
     3 (*>*)
     4 
     5 section {* Concrete Syntax \label{sec:concrete-syntax} *}
     6 
     7 text {*
     8   Concerning Isabelle's ``inner'' language of simply-typed @{text
     9   \<lambda>}-calculus, the core concept of Isabelle's elaborate
    10   infrastructure for concrete syntax is that of general
    11   \bfindex{mixfix annotations}.  Associated with any kind of constant
    12   declaration, mixfixes affect both the grammar productions for the
    13   parser and output templates for the pretty printer.
    14 
    15   In full generality, the whole affair of parser and pretty printer
    16   configuration is rather subtle, see also \cite{isabelle-ref}.
    17   Syntax specifications given by end-users need to interact properly
    18   with the existing setup of Isabelle/Pure and Isabelle/HOL.  It is
    19   particularly important to get the precedence of new syntactic
    20   constructs right, avoiding ambiguities with existing elements.
    21 
    22   \medskip Subsequently we introduce a few simple syntax declaration
    23   forms that already cover most common situations fairly well.
    24 *}
    25 
    26 
    27 subsection {* Infix Annotations *}
    28 
    29 text {*
    30   Syntax annotations may be included wherever constants are declared
    31   directly or indirectly, including \isacommand{consts},
    32   \isacommand{constdefs}, or \isacommand{datatype} (for the
    33   constructor operations).  Type-constructors may be annotated as
    34   well, although this is less frequently encountered in practice
    35   (@{text "*"} and @{text "+"} types may come to mind).
    36 
    37   Infix declarations\index{infix annotations} provide a useful special
    38   case of mixfixes, where users need not care about the full details
    39   of priorities, nesting, spacing, etc.  The following example of the
    40   exclusive-or operation on boolean values illustrates typical infix
    41   declarations arising in practice.
    42 *}
    43 
    44 constdefs
    45   xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "[+]" 60)
    46   "A [+] B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
    47 
    48 text {*
    49   \noindent Now @{text "xor A B"} and @{text "A [+] B"} refer to the
    50   same expression internally.  Any curried function with at least two
    51   arguments may be associated with infix syntax.  For partial
    52   applications with less than two operands there is a special notation
    53   with \isa{op} prefix: @{text xor} without arguments is represented
    54   as @{text "op [+]"}; together with plain prefix application this
    55   turns @{text "xor A"} into @{text "op [+] A"}.
    56 
    57   \medskip The string @{text [source] "[+]"} in the above annotation
    58   refers to the bit of concrete syntax to represent the operator,
    59   while the number @{text 60} determines the precedence of the
    60   construct (i.e.\ the syntactic priorities of the arguments and
    61   result).
    62 
    63   As it happens, Isabelle/HOL already spends many popular combinations
    64   of ASCII symbols for its own use, including both @{text "+"} and
    65   @{text "++"}.  Slightly more awkward combinations like the present
    66   @{text "[+]"} tend to be available for user extensions.  The current
    67   arrangement of inner syntax may be inspected via
    68   \commdx{print\protect\_syntax}, albeit its output is enormous.
    69 
    70   Operator precedence also needs some special considerations.  The
    71   admissible range is 0--1000.  Very low or high priorities are
    72   basically reserved for the meta-logic.  Syntax of Isabelle/HOL
    73   mainly uses the range of 10--100: the equality infix @{text "="} is
    74   centered at 50, logical connectives (like @{text "\<or>"} and @{text
    75   "\<and>"}) are below 50, and algebraic ones (like @{text "+"} and @{text
    76   "*"}) above 50.  User syntax should strive to coexist with common
    77   HOL forms, or use the mostly unused range 100--900.
    78 
    79   The keyword \isakeyword{infixl} specifies an infix operator that is
    80   nested to the \emph{left}: in iterated applications the more complex
    81   expression appears on the left-hand side: @{term "A [+] B [+] C"}
    82   stands for @{text "(A [+] B) [+] C"}.  Similarly,
    83   \isakeyword{infixr} specifies to nesting to the \emph{right},
    84   reading @{term "A [+] B [+] C"} as @{text "A [+] (B [+] C)"}.  In
    85   contrast, a \emph{non-oriented} declaration via \isakeyword{infix}
    86   would render @{term "A [+] B [+] C"} illegal, but demand explicit
    87   parentheses to indicate the intended grouping.
    88 *}
    89 
    90 
    91 subsection {* Mathematical Symbols \label{sec:syntax-symbols} *}
    92 
    93 text {*
    94   Concrete syntax based on plain ASCII characters has its inherent
    95   limitations.  Rich mathematical notation demands a larger repertoire
    96   of glyphs.  Several standards of extended character sets have been
    97   proposed over decades, but none has become universally available so
    98   far.  Isabelle supports a generic notion of \bfindex{symbols} as the
    99   smallest entities of source text, without referring to internal
   100   encodings.  There are three kinds of such ``generalized
   101   characters'':
   102 
   103   \begin{enumerate}
   104 
   105   \item 7-bit ASCII characters
   106 
   107   \item named symbols: \verb,\,\verb,<,$ident$\verb,>,
   108 
   109   \item named control symbols: \verb,\,\verb,<^,$ident$\verb,>,
   110 
   111   \end{enumerate}
   112 
   113   Here $ident$ may be any identifier according to the usual Isabelle
   114   conventions.  This results in an infinite store of symbols, whose
   115   interpretation is left to further front-end tools.  For example,
   116   both the user-interface of Proof~General + X-Symbol and the Isabelle
   117   document processor (see \S\ref{sec:document-preparation}) display
   118   the \verb,\,\verb,<forall>, symbol really as @{text \<forall>}.
   119 
   120   A list of standard Isabelle symbols is given in
   121   \cite[appendix~A]{isabelle-sys}.  Users may introduce their own
   122   interpretation of further symbols by configuring the appropriate
   123   front-end tool accordingly, e.g.\ by defining certain {\LaTeX}
   124   macros (see also \S\ref{sec:doc-prep-symbols}).  There are also a
   125   few predefined control symbols, such as \verb,\,\verb,<^sub>, and
   126   \verb,\,\verb,<^sup>, for sub- and superscript of the subsequent
   127   (printable) symbol, respectively.  For example, \verb,A\<^sup>\<star>, is
   128   output as @{text "A\<^sup>\<star>"}.
   129 
   130   \medskip The following version of our @{text xor} definition uses a
   131   standard Isabelle symbol to achieve typographically more pleasing
   132   output than before.
   133 *}
   134 
   135 (*<*)
   136 hide const xor
   137 ML_setup {* Context.>> (Theory.add_path "version1") *}
   138 (*>*)
   139 constdefs
   140   xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "\<oplus>" 60)
   141   "A \<oplus> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
   142 (*<*)
   143 local
   144 (*>*)
   145 
   146 text {*
   147   \noindent The X-Symbol package within Proof~General provides several
   148   input methods to enter @{text \<oplus>} in the text.  If all fails one may
   149   just type a named entity \verb,\,\verb,<oplus>, by hand; the display
   150   will be adapted immediately after continuing input.
   151 
   152   \medskip A slightly more refined scheme is to provide alternative
   153   syntax via the \bfindex{print mode} concept of Isabelle (see also
   154   \cite{isabelle-ref}).  By convention, the mode of ``$xsymbols$'' is
   155   enabled whenever Proof~General's X-Symbol mode (or {\LaTeX} output)
   156   is active.  Now consider the following hybrid declaration of @{text
   157   xor}.
   158 *}
   159 
   160 (*<*)
   161 hide const xor
   162 ML_setup {* Context.>> (Theory.add_path "version2") *}
   163 (*>*)
   164 constdefs
   165   xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "[+]\<ignore>" 60)
   166   "A [+]\<ignore> B \<equiv> (A \<and> \<not> B) \<or> (\<not> A \<and> B)"
   167 
   168 syntax (xsymbols)
   169   xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "\<oplus>\<ignore>" 60)
   170 (*<*)
   171 local
   172 (*>*)
   173 
   174 text {*
   175   The \commdx{syntax} command introduced here acts like
   176   \isakeyword{consts}, but without declaring a logical constant; an
   177   optional print mode specification may be given, too.  Note that the
   178   type declaration given above merely serves for syntactic purposes,
   179   and is not checked for consistency with the real constant.
   180 
   181   \medskip We may now write @{text "A [+] B"} or @{text "A \<oplus> B"} in
   182   input, while output uses the nicer syntax of $xsymbols$, provided
   183   that print mode is active.  Such an arrangement is particularly
   184   useful for interactive development, where users may type plain ASCII
   185   text, but gain improved visual feedback from the system.
   186 
   187   \begin{warn}
   188   Alternative syntax declarations are apt to result in varying
   189   occurrences of concrete syntax in the input sources.  Isabelle
   190   provides no systematic way to convert alternative syntax expressions
   191   back and forth; print modes only affect situations where formal
   192   entities are pretty printed by the Isabelle process (e.g.\ output of
   193   terms and types), but not the original theory text.
   194   \end{warn}
   195 
   196   \medskip The following variant makes the alternative @{text \<oplus>}
   197   notation only available for output.  Thus we may enforce input
   198   sources to refer to plain ASCII only, but effectively disable
   199   cut-and-paste from output at the same time.
   200 *}
   201 
   202 syntax (xsymbols output)
   203   xor :: "bool \<Rightarrow> bool \<Rightarrow> bool"    (infixl "\<oplus>\<ignore>" 60)
   204 
   205 
   206 subsection {* Prefix Annotations *}
   207 
   208 text {*
   209   Prefix syntax annotations\index{prefix annotation} are just another
   210   degenerate form of mixfixes \cite{isabelle-ref}, without any
   211   template arguments or priorities --- just some bits of literal
   212   syntax.  The following example illustrates this idea idea by
   213   associating common symbols with the constructors of a datatype.
   214 *}
   215 
   216 datatype currency =
   217     Euro nat    ("\<euro>")
   218   | Pounds nat  ("\<pounds>")
   219   | Yen nat     ("\<yen>")
   220   | Dollar nat  ("$")
   221 
   222 text {*
   223   \noindent Here the mixfix annotations on the rightmost column happen
   224   to consist of a single Isabelle symbol each: \verb,\,\verb,<euro>,,
   225   \verb,\,\verb,<pounds>,, \verb,\,\verb,<yen>,, and \verb,$,.  Recall
   226   that a constructor like @{text Euro} actually is a function @{typ
   227   "nat \<Rightarrow> currency"}.  An expression like @{text "Euro 10"} will be
   228   printed as @{term "\<euro> 10"}; only the head of the application is
   229   subject to our concrete syntax.  This simple form already achieves
   230   conformance with notational standards of the European Commission.
   231 
   232   Prefix syntax also works for plain \isakeyword{consts} or
   233   \isakeyword{constdefs}, of course.
   234 *}
   235 
   236 
   237 subsection {* Syntax Translations \label{sec:syntax-translations} *}
   238 
   239 text{*
   240   Mixfix syntax annotations work well in those situations where
   241   particular constant application forms need to be decorated by
   242   concrete syntax; just reconsider @{text "xor A B"} versus @{text "A
   243   \<oplus> B"} covered before.  Occasionally the relationship between some
   244   piece of notation and its internal form is slightly more involved.
   245   Here the concept of \bfindex{syntax translations} enters the scene.
   246 
   247   Using the raw \isakeyword{syntax}\index{syntax (command)} command we
   248   may introduce uninterpreted notational elements, while
   249   \commdx{translations} relates input forms with more complex logical
   250   expressions.  This essentially provides a simple mechanism for
   251   syntactic macros; even heavier transformations may be written in ML
   252   \cite{isabelle-ref}.
   253 
   254   \medskip A typical example of syntax translations is to decorate
   255   relational expressions (i.e.\ set-membership of tuples) with
   256   handsome symbolic notation, such as @{text "(x, y) \<in> sim"} versus
   257   @{text "x \<approx> y"}.
   258 *}
   259 
   260 consts
   261   sim :: "('a \<times> 'a) set"
   262 
   263 syntax
   264   "_sim" :: "'a \<Rightarrow> 'a \<Rightarrow> bool"    (infix "\<approx>" 50)
   265 translations
   266   "x \<approx> y" \<rightleftharpoons> "(x, y) \<in> sim"
   267 
   268 text {*
   269   \noindent Here the name of the dummy constant @{text "_sim"} does
   270   not really matter, as long as it is not used elsewhere.  Prefixing
   271   an underscore is a common convention.  The \isakeyword{translations}
   272   declaration already uses concrete syntax on the left-hand side;
   273   internally we relate a raw application @{text "_sim x y"} with
   274   @{text "(x, y) \<in> sim"}.
   275 
   276   \medskip Another common application of syntax translations is to
   277   provide variant versions of fundamental relational expressions, such
   278   as @{text \<noteq>} for negated equalities.  The following declaration
   279   stems from Isabelle/HOL itself:
   280 *}
   281 
   282 syntax "_not_equal" :: "'a \<Rightarrow> 'a \<Rightarrow> bool"    (infixl "\<noteq>\<ignore>" 50)
   283 translations "x \<noteq>\<ignore> y" \<rightleftharpoons> "\<not> (x = y)"
   284 
   285 text {*
   286   \noindent Normally one would introduce derived concepts like this
   287   within the logic, using \isakeyword{consts} + \isakeyword{defs}
   288   instead of \isakeyword{syntax} + \isakeyword{translations}.  The
   289   present formulation has the virtue that expressions are immediately
   290   replaced by the ``definition'' upon parsing; the effect is reversed
   291   upon printing.
   292 
   293   Simulating definitions via translations is adequate for very basic
   294   principles, where a new representation is a trivial variation on an
   295   existing one.  On the other hand, syntax translations do not scale
   296   up well to large hierarchies of concepts built on each other.
   297 *}
   298 
   299 
   300 section {* Document Preparation \label{sec:document-preparation} *}
   301 
   302 text {*
   303   Isabelle/Isar is centered around the concept of \bfindex{formal
   304   proof documents}\index{documents|bold}.  The ultimate result of a
   305   formal development effort is meant to be a human-readable record,
   306   presented as browsable PDF file or printed on paper.  The overall
   307   document structure follows traditional mathematical articles, with
   308   sections, intermediate explanations, definitions, theorems and
   309   proofs.
   310 
   311   The Isar proof language \cite{Wenzel-PhD}, which is not covered in
   312   this book, admits to write formal proof texts that are acceptable
   313   both to the machine and human readers at the same time.  Thus
   314   marginal comments and explanations may be kept at a minimum.  Even
   315   without proper coverage of human-readable proofs, Isabelle document
   316   preparation is very useful to produce formally derived texts.
   317   Unstructured proof scripts given here may be just ignored by
   318   readers, or intentionally suppressed from the text by the writer
   319   (see also \S\ref{sec:doc-prep-suppress}).
   320 
   321   \medskip The Isabelle document preparation system essentially acts
   322   as a front-end to {\LaTeX}.  After checking specifications and
   323   proofs formally, the theory sources are turned into typesetting
   324   instructions in a schematic manner.  This enables users to write
   325   authentic reports on theory developments with little effort, where
   326   most consistency checks are handled by the system.
   327 *}
   328 
   329 
   330 subsection {* Isabelle Sessions *}
   331 
   332 text {*
   333   In contrast to the highly interactive mode of Isabelle/Isar theory
   334   development, the document preparation stage essentially works in
   335   batch-mode.  An Isabelle \bfindex{session} consists of a collection
   336   of theory source files that contribute to an output document
   337   eventually.  Each session is derived from a single parent, usually
   338   an object-logic image like \texttt{HOL}.  This results in an overall
   339   tree structure, which is reflected by the output location in the
   340   file system (usually rooted at \verb,~/isabelle/browser_info,).
   341 
   342   \medskip Here is the canonical arrangement of sources of a session
   343   called \texttt{MySession}:
   344 
   345   \begin{itemize}
   346 
   347   \item Directory \texttt{MySession} holds the required theory files
   348   $T@1$\texttt{.thy}, \dots, $T@n$\texttt{.thy}.
   349 
   350   \item File \texttt{MySession/ROOT.ML} holds appropriate ML commands
   351   for loading all wanted theories, usually just
   352   ``\texttt{use_thy"$T@i$";}'' for any $T@i$ in leaf position of the
   353   dependency graph.
   354 
   355   \item Directory \texttt{MySession/document} contains everything
   356   required for the {\LaTeX} stage; only \texttt{root.tex} needs to be
   357   provided initially.
   358 
   359   The latter file holds appropriate {\LaTeX} code to commence a
   360   document (\verb,\documentclass, etc.), and to include the generated
   361   files $T@i$\texttt{.tex} for each theory.  The generated
   362   \texttt{session.tex} will contain {\LaTeX} commands to include all
   363   generated files in topologically sorted order, so
   364   \verb,\input{session}, in \texttt{root.tex} does the job in most
   365   situations.
   366 
   367   \item \texttt{IsaMakefile} holds appropriate dependencies and
   368   invocations of Isabelle tools to control the batch job.  In fact,
   369   several sessions may be controlled by the same \texttt{IsaMakefile}.
   370   See also \cite{isabelle-sys} for further details, especially on
   371   \texttt{isatool usedir} and \texttt{isatool make}.
   372 
   373   \end{itemize}
   374 
   375   With everything put in its proper place, \texttt{isatool make}
   376   should be sufficient to process the Isabelle session completely,
   377   with the generated document appearing in its proper place.
   378 
   379   \medskip In reality, users may want to have \texttt{isatool mkdir}
   380   generate an initial working setup without further ado.  For example,
   381   a new session \texttt{MySession} derived from \texttt{HOL} may be
   382   produced as follows:
   383 
   384 \begin{verbatim}
   385   isatool mkdir HOL MySession
   386   isatool make
   387 \end{verbatim}
   388 
   389   This processes the session with sensible default options, including
   390   verbose mode to tell the user where the ultimate results will
   391   appear.  The above dry run should already be able to produce a
   392   single page of output (with a dummy title, empty table of contents
   393   etc.).  Any failure at that stage is likely to indicate technical
   394   problems with the user's {\LaTeX} installation.\footnote{Especially
   395   make sure that \texttt{pdflatex} is present; if all fails one may
   396   fall back on DVI output by changing \texttt{usedir} options in
   397   \texttt{IsaMakefile} \cite{isabelle-sys}.}
   398 
   399   \medskip One may now start to populate the directory
   400   \texttt{MySession}, and the file \texttt{MySession/ROOT.ML}
   401   accordingly.  \texttt{MySession/document/root.tex} should also be
   402   adapted at some point; the default version is mostly
   403   self-explanatory.  Note that \verb,\isabellestyle, enables
   404   fine-tuning of the general appearance of characters and mathematical
   405   symbols (see also \S\ref{sec:doc-prep-symbols}).
   406 
   407   Especially observe inclusion of the {\LaTeX} packages
   408   \texttt{isabelle} (mandatory), and \texttt{isabellesym} (required
   409   for mathematical symbols), and the final \texttt{pdfsetup} (provides
   410   handsome defaults for \texttt{hyperref}, including URL markup).
   411   Further packages may be required in particular applications, e.g.\
   412   for unusual Isabelle symbols.
   413 
   414   \medskip Additional files for the {\LaTeX} stage may be included in
   415   the directory \texttt{MySession/document}, too, such as {\TeX}
   416   sources or graphics).  In particular, adding \texttt{root.bib} here
   417   (with that specific name) causes an automatic run of \texttt{bibtex}
   418   to process a bibliographic database; see also \texttt{isatool
   419   document} covered in \cite{isabelle-sys}.
   420 
   421   \medskip Any failure of the document preparation phase in an
   422   Isabelle batch session leaves the generated sources in their target
   423   location (as pointed out by the accompanied error message).  This
   424   enables users to trace {\LaTeX} at the file positions of the
   425   generated material.
   426 *}
   427 
   428 
   429 subsection {* Structure Markup *}
   430 
   431 text {*
   432   The large-scale structure of Isabelle documents follows existing
   433   {\LaTeX} conventions, with chapters, sections, subsubsections etc.
   434   The Isar language includes separate \bfindex{markup commands}, which
   435   do not affect the formal meaning of a theory (or proof), but result
   436   in corresponding {\LaTeX} elements.
   437 
   438   There are separate markup commands depending on the textual context:
   439   in header position (just before \isakeyword{theory}), within the
   440   theory body, or within a proof.  The header needs to be treated
   441   specially here, since ordinary theory and proof commands may only
   442   occur \emph{after} the initial \isakeyword{theory} specification.
   443 
   444   \medskip
   445 
   446   \begin{tabular}{llll}
   447   header & theory & proof & default meaning \\\hline
   448     & \commdx{chapter} & & \verb,\chapter, \\
   449   \commdx{header} & \commdx{section} & \commdx{sect} & \verb,\section, \\
   450     & \commdx{subsection} & \commdx{subsect} & \verb,\subsection, \\
   451     & \commdx{subsubsection} & \commdx{subsubsect} & \verb,\subsubsection, \\
   452   \end{tabular}
   453 
   454   \medskip
   455 
   456   From the Isabelle perspective, each markup command takes a single
   457   $text$ argument (delimited by \verb,",\dots\verb,", or
   458   \verb,{,\verb,*,~\dots~\verb,*,\verb,},).  After stripping any
   459   surrounding white space, the argument is passed to a {\LaTeX} macro
   460   \verb,\isamarkupXYZ, for any command \isakeyword{XYZ}.  These macros
   461   are defined in \verb,isabelle.sty, according to the meaning given in
   462   the rightmost column above.
   463 
   464   \medskip The following source fragment illustrates structure markup
   465   of a theory.  Note that {\LaTeX} labels may be included inside of
   466   section headings as well.
   467 
   468   \begin{ttbox}
   469   header {\ttlbrace}* Some properties of Foo Bar elements *{\ttrbrace}
   470 
   471   theory Foo_Bar = Main:
   472 
   473   subsection {\ttlbrace}* Basic definitions *{\ttrbrace}
   474 
   475   consts
   476     foo :: \dots
   477     bar :: \dots
   478 
   479   defs \dots
   480 
   481   subsection {\ttlbrace}* Derived rules *{\ttrbrace}
   482 
   483   lemma fooI: \dots
   484   lemma fooE: \dots
   485 
   486   subsection {\ttlbrace}* Main theorem {\ttback}label{\ttlbrace}sec:main-theorem{\ttrbrace} *{\ttrbrace}
   487 
   488   theorem main: \dots
   489 
   490   end
   491   \end{ttbox}
   492 
   493   Users may occasionally want to change the meaning of markup
   494   commands, say via \verb,\renewcommand, in \texttt{root.tex};
   495   \verb,\isamarkupheader, is a good candidate for some tuning, e.g.\
   496   moving it up in the hierarchy to become \verb,\chapter,.
   497 
   498 \begin{verbatim}
   499   \renewcommand{\isamarkupheader}[1]{\chapter{#1}}
   500 \end{verbatim}
   501 
   502   \noindent Certainly, this requires to change the default
   503   \verb,\documentclass{article}, in \texttt{root.tex} to something
   504   that supports the notion of chapters in the first place, e.g.\
   505   \verb,\documentclass{report},.
   506 
   507   \medskip The {\LaTeX} macro \verb,\isabellecontext, is maintained to
   508   hold the name of the current theory context.  This is particularly
   509   useful for document headings:
   510 
   511 \begin{verbatim}
   512   \renewcommand{\isamarkupheader}[1]
   513   {\chapter{#1}\markright{THEORY~\isabellecontext}}
   514 \end{verbatim}
   515 
   516   \noindent Make sure to include something like
   517   \verb,\pagestyle{headings}, in \texttt{root.tex}; the document
   518   should have more than 2 pages to show the effect.
   519 *}
   520 
   521 
   522 subsection {* Formal Comments and Antiquotations *}
   523 
   524 text {*
   525   Isabelle source comments, which are of the form
   526   \verb,(,\verb,*,~\dots~\verb,*,\verb,),, essentially act like white
   527   space and do not really contribute to the content.  They mainly
   528   serve technical purposes to mark certain oddities in the raw input
   529   text.  In contrast, \bfindex{formal comments} are portions of text
   530   that are associated with formal Isabelle/Isar commands
   531   (\bfindex{marginal comments}), or as standalone paragraphs within a
   532   theory or proof context (\bfindex{text blocks}).
   533 
   534   \medskip Marginal comments are part of each command's concrete
   535   syntax \cite{isabelle-ref}; the common form is ``\verb,--,~$text$''
   536   where $text$ is delimited by \verb,",\dots\verb,", or
   537   \verb,{,\verb,*,~\dots~\verb,*,\verb,}, as before.  Multiple
   538   marginal comments may be given at the same time.  Here is a simple
   539   example:
   540 *}
   541 
   542 lemma "A --> A"
   543   -- "a triviality of propositional logic"
   544   -- "(should not really bother)"
   545   by (rule impI) -- "implicit assumption step involved here"
   546 
   547 text {*
   548   \noindent The above output has been produced as follows:
   549 
   550 \begin{verbatim}
   551   lemma "A --> A"
   552     -- "a triviality of propositional logic"
   553     -- "(should not really bother)"
   554     by (rule impI) -- "implicit assumption step involved here"
   555 \end{verbatim}
   556 
   557   From the {\LaTeX} viewpoint, ``\verb,--,'' acts like a markup
   558   command, associated with the macro \verb,\isamarkupcmt, (taking a
   559   single argument).
   560 
   561   \medskip Text blocks are introduced by the commands \bfindex{text}
   562   and \bfindex{txt}, for theory and proof contexts, respectively.
   563   Each takes again a single $text$ argument, which is interpreted as a
   564   free-form paragraph in {\LaTeX} (surrounded by some additional
   565   vertical space).  This behavior may be changed by redefining the
   566   {\LaTeX} environments of \verb,isamarkuptext, or
   567   \verb,isamarkuptxt,, respectively (via \verb,\renewenvironment,) The
   568   text style of the body is determined by \verb,\isastyletext, and
   569   \verb,\isastyletxt,; the default setup uses a smaller font within
   570   proofs.
   571 
   572   \medskip The $text$ part of each of the various markup commands
   573   considered so far essentially inserts \emph{quoted material} into a
   574   formal text, mainly for instruction of the reader.  An
   575   \bfindex{antiquotation} is again a formal object embedded into such
   576   an informal portion.  The interpretation of antiquotations is
   577   limited to some well-formedness checks, with the result being pretty
   578   printed to the resulting document.  So quoted text blocks together
   579   with antiquotations provide very handsome means to reference formal
   580   entities with good confidence in getting the technical details right
   581   (especially syntax and types).
   582 
   583   The general syntax of antiquotations is as follows:
   584   \texttt{{\at}{\ttlbrace}$name$ $arguments${\ttrbrace}}, or
   585   \texttt{{\at}{\ttlbrace}$name$ [$options$] $arguments${\ttrbrace}}
   586   for a comma-separated list of options consisting of a $name$ or
   587   \texttt{$name$=$value$}.  The syntax of $arguments$ depends on the
   588   kind of antiquotation, it generally follows the same conventions for
   589   types, terms, or theorems as in the formal part of a theory.
   590 
   591   \medskip Here is an example of the quotation-antiquotation
   592   technique: @{term "%x y. x"} is a well-typed term.
   593 
   594   \medskip\noindent The above output has been produced as follows:
   595   \begin{ttbox}
   596 text {\ttlbrace}*
   597   Here is an example of the quotation-antiquotation technique:
   598   {\at}{\ttlbrace}term "%x y. x"{\ttrbrace} is a well-typed term.
   599 *{\ttrbrace}
   600   \end{ttbox}
   601 
   602   From the notational change of the ASCII character \verb,%, to the
   603   symbol @{text \<lambda>} we see that the term really got printed by the
   604   system (after parsing and type-checking) --- document preparation
   605   enables symbolic output by default.
   606 
   607   \medskip The next example includes an option to modify the
   608   \verb,show_types, flag of Isabelle:
   609   \texttt{{\at}}\verb,{term [show_types] "%x y. x"}, produces @{term
   610   [show_types] "%x y. x"}.  Type-inference has figured out the most
   611   general typings in the present (theory) context.  Note that term
   612   fragments may acquire different typings due to constraints imposed
   613   by previous text (say within a proof), e.g.\ due to the main goal
   614   statement given beforehand.
   615 
   616   \medskip Several further kinds of antiquotations (and options) are
   617   available \cite{isabelle-sys}.  Here are a few commonly used
   618   combinations:
   619 
   620   \medskip
   621 
   622   \begin{tabular}{ll}
   623   \texttt{\at}\verb,{typ,~$\tau$\verb,}, & print type $\tau$ \\
   624   \texttt{\at}\verb,{term,~$t$\verb,}, & print term $t$ \\
   625   \texttt{\at}\verb,{prop,~$\phi$\verb,}, & print proposition $\phi$ \\
   626   \texttt{\at}\verb,{prop [display],~$\phi$\verb,}, & print large proposition $\phi$ (with linebreaks) \\
   627   \texttt{\at}\verb,{prop [source],~$\phi$\verb,}, & check proposition $\phi$, print its input \\
   628   \texttt{\at}\verb,{thm,~$a$\verb,}, & print fact $a$ \\
   629   \texttt{\at}\verb,{thm,~$a$~\verb,[no_vars]}, & print fact $a$, fixing schematic variables \\
   630   \texttt{\at}\verb,{thm [source],~$a$\verb,}, & check validity of fact $a$, print its name \\
   631   \texttt{\at}\verb,{text,~$s$\verb,}, & print uninterpreted text $s$ \\
   632   \end{tabular}
   633 
   634   \medskip
   635 
   636   Note that \attrdx{no_vars} given above is \emph{not} an
   637   antiquotation option, but an attribute of the theorem argument given
   638   here.  This might be useful with a diagnostic command like
   639   \isakeyword{thm}, too.
   640 
   641   \medskip The \texttt{\at}\verb,{text, $s$\verb,}, antiquotation is
   642   particularly interesting.  Embedding uninterpreted text within an
   643   informal body might appear useless at first sight.  Here the key
   644   virtue is that the string $s$ is processed as Isabelle output,
   645   interpreting Isabelle symbols appropriately.
   646 
   647   For example, \texttt{\at}\verb,{text "\<forall>\<exists>"}, produces @{text
   648   "\<forall>\<exists>"}, according to the standard interpretation of these symbol
   649   (cf.\ \S\ref{sec:doc-prep-symbols}).  Thus we achieve consistent
   650   mathematical notation in both the formal and informal parts of the
   651   document very easily.  Manual {\LaTeX} code would leave more control
   652   over the typesetting, but is also slightly more tedious.
   653 *}
   654 
   655 
   656 subsection {* Interpretation of Symbols \label{sec:doc-prep-symbols} *}
   657 
   658 text {*
   659   As has been pointed out before (\S\ref{sec:syntax-symbols}),
   660   Isabelle symbols are the smallest syntactic entities --- a
   661   straightforward generalization of ASCII characters.  While Isabelle
   662   does not impose any interpretation of the infinite collection of
   663   named symbols, {\LaTeX} documents show canonical glyphs for certain
   664   standard symbols \cite[appendix~A]{isabelle-sys}.
   665 
   666   The {\LaTeX} code produced from Isabelle text follows a relatively
   667   simple scheme.  Users may wish to tune the final appearance by
   668   redefining certain macros, say in \texttt{root.tex} of the document.
   669 
   670   \begin{enumerate}
   671 
   672   \item 7-bit ASCII characters: letters \texttt{A\dots Z} and
   673   \texttt{a\dots z} are output verbatim, digits are passed as an
   674   argument to the \verb,\isadigit, macro, other characters are
   675   replaced by specifically named macros of the form
   676   \verb,\isacharXYZ,.
   677 
   678   \item Named symbols: \verb,\,\verb,<,$XYZ$\verb,>, become
   679   \verb,{\isasym,$XYZ$\verb,}, each (note the additional braces).
   680 
   681   \item Named control symbols: \verb,{\isasym,$XYZ$\verb,}, become
   682   \verb,\isactrl,$XYZ$ each; subsequent symbols may act as arguments
   683   if the corresponding macro is defined accordingly.
   684 
   685   \end{enumerate}
   686 
   687   Users may occasionally wish to give new {\LaTeX} interpretations of
   688   named symbols; this merely requires an appropriate definition of
   689   \verb,\,\verb,<,$XYZ$\verb,>, (see \texttt{isabelle.sty} for working
   690   examples).  Control symbols are slightly more difficult to get
   691   right, though.
   692 
   693   \medskip The \verb,\isabellestyle, macro provides a high-level
   694   interface to tune the general appearance of individual symbols.  For
   695   example, \verb,\isabellestyle{it}, uses the italics text style to
   696   mimic the general appearance of the {\LaTeX} math mode; double
   697   quotes are not printed at all.  The resulting quality of
   698   typesetting is quite good, so this should usually be the default
   699   style for real production work that gets distributed to a broader
   700   audience.
   701 *}
   702 
   703 
   704 subsection {* Suppressing Output \label{sec:doc-prep-suppress} *}
   705 
   706 text {*
   707   By default, Isabelle's document system generates a {\LaTeX} source
   708   file for each theory that happens to get loaded while running the
   709   session.  The generated \texttt{session.tex} will include all of
   710   these in order of appearance, which in turn gets included by the
   711   standard \texttt{root.tex}.  Certainly one may change the order or
   712   suppress unwanted theories by ignoring \texttt{session.tex} and
   713   include individual files in \texttt{root.tex} by hand.  On the other
   714   hand, such an arrangement requires additional maintenance chores
   715   whenever the collection of theories changes.
   716 
   717   Alternatively, one may tune the theory loading process in
   718   \texttt{ROOT.ML} itself: traversal of the theory dependency graph
   719   may be fine-tuned by adding \verb,use_thy, invocations, although
   720   topological sorting still has to be observed.  Moreover, the ML
   721   operator \verb,no_document, temporarily disables document generation
   722   while executing a theory loader command; its usage is like this:
   723 
   724 \begin{verbatim}
   725   no_document use_thy "T";
   726 \end{verbatim}
   727 
   728   \medskip Theory output may also be suppressed in smaller portions.
   729   For example, research articles, or slides usually do not include the
   730   formal content in full.  In order to delimit \bfindex{ignored
   731   material} special source comments
   732   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), and
   733   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), may be included in the
   734   text.  Only the document preparation system is affected, the formal
   735   checking the theory is performed unchanged.
   736 
   737   In the following example we suppress the slightly formalistic
   738   \isakeyword{theory} + \isakeyword{end} surroundings a theory.
   739 
   740   \medskip
   741 
   742   \begin{tabular}{l}
   743   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
   744   \texttt{theory T = Main:} \\
   745   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
   746   ~~$\vdots$ \\
   747   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
   748   \texttt{end} \\
   749   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
   750   \end{tabular}
   751 
   752   \medskip
   753 
   754   Text may be suppressed in a fine-grained manner.  We may even drop
   755   vital parts of a formal proof, pretending that things have been
   756   simpler than in reality.  For example, the following ``fully
   757   automatic'' proof is actually a fake:
   758 *}
   759 
   760 lemma "x \<noteq> (0::int) \<Longrightarrow> 0 < x * x"
   761   by (auto(*<*)simp add: int_less_le(*>*))
   762 
   763 text {*
   764   \noindent Here the real source of the proof has been as follows:
   765 
   766 \begin{verbatim}
   767   by (auto(*<*)simp add: int_less_le(*>*))
   768 \end{verbatim}
   769 %(*
   770 
   771   \medskip Ignoring portions of printed text does demand some care by
   772   the writer.  First of all, the writer is responsible not to
   773   obfuscate the underlying formal development in an unduly manner.  It
   774   is fairly easy to invalidate the remaining visible text, e.g.\ by
   775   referencing questionable formal items (strange definitions,
   776   arbitrary axioms etc.) that have been hidden from sight beforehand.
   777 
   778   Authentic reports of formal theories, say as part of a library,
   779   usually should refrain from suppressing parts of the text at all.
   780   Other users may need the full information for their own derivative
   781   work.  If a particular formalization appears inadequate for general
   782   public coverage, it is often more appropriate to think of a better
   783   way in the first place.
   784 
   785   \medskip Some technical subtleties of the
   786   \verb,(,\verb,*,\verb,<,\verb,*,\verb,),~\verb,(,\verb,*,\verb,>,\verb,*,\verb,),
   787   elements need to be kept in mind, too --- the system performs little
   788   sanity checks here.  Arguments of markup commands and formal
   789   comments must not be hidden, otherwise presentation fails.  Open and
   790   close parentheses need to be inserted carefully; it is fairly easy
   791   to hide the wrong parts, especially after rearranging the sources.
   792 
   793 *}
   794 
   795 (*<*)
   796 end
   797 (*>*)