doc-src/TutorialI/Documents/document/Documents.tex
changeset 12652 2d136f05e164
parent 12649 6e17f2ae9e16
child 12658 3939e7dea202
equal deleted inserted replaced
12651:930df4604b36 12652:2d136f05e164
     6 \isamarkupsection{Concrete Syntax \label{sec:concrete-syntax}%
     6 \isamarkupsection{Concrete Syntax \label{sec:concrete-syntax}%
     7 }
     7 }
     8 \isamarkuptrue%
     8 \isamarkuptrue%
     9 %
     9 %
    10 \begin{isamarkuptext}%
    10 \begin{isamarkuptext}%
    11 Concerning Isabelle's ``inner'' language of simply-typed \isa{{\isasymlambda}}-calculus, the core concept of Isabelle's elaborate infrastructure
    11 Concerning Isabelle's ``inner'' language of simply-typed \isa{{\isasymlambda}}-calculus, the core concept of Isabelle's elaborate
    12   for concrete syntax is that of general \bfindex{mixfix annotations}.
    12   infrastructure for concrete syntax is that of general
    13   Associated with any kind of name and type declaration, mixfixes give
    13   \bfindex{mixfix annotations}.  Associated with any kind of constant
    14   rise both to grammar productions for the parser and output templates
    14   declaration, mixfixes affect both the grammar productions for the
    15   for the pretty printer.
    15   parser and output templates for the pretty printer.
    16 
    16 
    17   In full generality, the whole affair of parser and pretty printer
    17   In full generality, the whole affair of parser and pretty printer
    18   configuration is rather subtle.  Any syntax specifications given by
    18   configuration is rather subtle, see \cite{isabelle-ref} for further
    19   end-users need to interact properly with the existing setup of
    19   details.  Any syntax specifications given by end-users need to
    20   Isabelle/Pure and Isabelle/HOL; see \cite{isabelle-ref} for further
    20   interact properly with the existing setup of Isabelle/Pure and
    21   details.  It is particularly important to get the precedence of new
    21   Isabelle/HOL.  It is particularly important to get the precedence of
    22   syntactic constructs right, avoiding ambiguities with existing
    22   new syntactic constructs right, avoiding ambiguities with existing
    23   elements.
    23   elements.
    24 
    24 
    25   \medskip Subsequently we introduce a few simple declaration forms
    25   \medskip Subsequently we introduce a few simple declaration forms
    26   that already cover the most common situations fairly well.%
    26   that already cover the most common situations fairly well.%
    27 \end{isamarkuptext}%
    27 \end{isamarkuptext}%
    41 
    41 
    42   Infix declarations\index{infix annotations} provide a useful special
    42   Infix declarations\index{infix annotations} provide a useful special
    43   case of mixfixes, where users need not care about the full details
    43   case of mixfixes, where users need not care about the full details
    44   of priorities, nesting, spacing, etc.  The subsequent example of the
    44   of priorities, nesting, spacing, etc.  The subsequent example of the
    45   exclusive-or operation on boolean values illustrates typical infix
    45   exclusive-or operation on boolean values illustrates typical infix
    46   declarations.%
    46   declarations arising in practice.%
    47 \end{isamarkuptext}%
    47 \end{isamarkuptext}%
    48 \isamarkuptrue%
    48 \isamarkuptrue%
    49 \isacommand{constdefs}\isanewline
    49 \isacommand{constdefs}\isanewline
    50 \ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isachardoublequote}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isanewline
    50 \ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isachardoublequote}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isanewline
    51 \ \ {\isachardoublequote}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
    51 \ \ {\isachardoublequote}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
    52 %
    52 %
    53 \begin{isamarkuptext}%
    53 \begin{isamarkuptext}%
    54 Any curried function with at least two arguments may be associated
    54 \noindent Now \isa{xor\ A\ B} and \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B} refer to the
    55   with infix syntax: \isa{xor\ A\ B} and \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B} refer to
    55   same expression internally.  Any curried function with at least two
    56   the same expression internally.  In partial applications with less
    56   arguments may be associated with infix syntax.  For partial
    57   than two operands there is a special notation with \isa{op} prefix:
    57   applications with less than two operands there is a special notation
    58   \isa{xor} without arguments is represented as \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}};
    58   with \isa{op} prefix: \isa{xor} without arguments is represented
    59   combined with plain prefix application this turns \isa{xor\ A}
    59   as \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}}; together with plain prefix application this
    60   into \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ A}.
    60   turns \isa{xor\ A} into \isa{op\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ A}.
    61 
    61 
    62   \medskip The string \isa{{\isachardoublequote}{\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isachardoublequote}} in the above declaration
    62   \medskip The string \isa{{\isachardoublequote}{\isacharbrackleft}{\isacharplus}{\isacharbrackright}{\isachardoublequote}} in the above annotation
    63   refers to the bit of concrete syntax to represent the operator,
    63   refers to the bit of concrete syntax to represent the operator,
    64   while the number \isa{{\isadigit{6}}{\isadigit{0}}} determines the precedence of the whole
    64   while the number \isa{{\isadigit{6}}{\isadigit{0}}} determines the precedence of the
    65   construct.
    65   construct (i.e.\ the syntactic priorities of the arguments and
       
    66   result).
    66 
    67 
    67   As it happens, Isabelle/HOL already spends many popular combinations
    68   As it happens, Isabelle/HOL already spends many popular combinations
    68   of ASCII symbols for its own use, including both \isa{{\isacharplus}} and
    69   of ASCII symbols for its own use, including both \isa{{\isacharplus}} and
    69   \isa{{\isacharplus}{\isacharplus}}.  Slightly more awkward combinations like the present
    70   \isa{{\isacharplus}{\isacharplus}}.  Slightly more awkward combinations like the present
    70   \isa{{\isacharbrackleft}{\isacharplus}{\isacharbrackright}} tend to be available for user extensions.  The current
    71   \isa{{\isacharbrackleft}{\isacharplus}{\isacharbrackright}} tend to be available for user extensions.  The current
    79   HOL forms, or use the mostly unused range 100--900.
    80   HOL forms, or use the mostly unused range 100--900.
    80 
    81 
    81   \medskip The keyword \isakeyword{infixl} specifies an operator that
    82   \medskip The keyword \isakeyword{infixl} specifies an operator that
    82   is nested to the \emph{left}: in iterated applications the more
    83   is nested to the \emph{left}: in iterated applications the more
    83   complex expression appears on the left-hand side: \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} stands for \isa{{\isacharparenleft}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B{\isacharparenright}\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C}.  Similarly,
    84   complex expression appears on the left-hand side: \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} stands for \isa{{\isacharparenleft}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B{\isacharparenright}\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C}.  Similarly,
    84   \isakeyword{infixr} refers to nesting to the \emph{right}, reading
    85   \isakeyword{infixr} specifies to nesting to the \emph{right},
    85   \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} as \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ {\isacharparenleft}B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C{\isacharparenright}}.  In contrast,
    86   reading \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} as \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ {\isacharparenleft}B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C{\isacharparenright}}.  In
    86   a \emph{non-oriented} declaration via \isakeyword{infix} would
    87   contrast, a \emph{non-oriented} declaration via \isakeyword{infix}
    87   always demand explicit parentheses.
    88   would have rendered \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C} illegal, but demand
    88 
    89   explicit parentheses about the intended grouping.%
    89   Many binary operations observe the associative law, so the exact
       
    90   grouping does not matter.  Nevertheless, formal statements need be
       
    91   given in a particular format, associativity needs to be treated
       
    92   explicitly within the logic.  Exclusive-or is happens to be
       
    93   associative, as shown below.%
       
    94 \end{isamarkuptext}%
       
    95 \isamarkuptrue%
       
    96 \isacommand{lemma}\ xor{\isacharunderscore}assoc{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B{\isacharparenright}\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C\ {\isacharequal}\ A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ {\isacharparenleft}B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C{\isacharparenright}{\isachardoublequote}\isanewline
       
    97 \ \ \isamarkupfalse%
       
    98 \isacommand{by}\ {\isacharparenleft}auto\ simp\ add{\isacharcolon}\ xor{\isacharunderscore}def{\isacharparenright}\isamarkupfalse%
       
    99 %
       
   100 \begin{isamarkuptext}%
       
   101 Such rules may be used in simplification to regroup nested
       
   102   expressions as required.  Note that the system would actually print
       
   103   the above statement as \isa{A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C\ {\isacharequal}\ A\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ {\isacharparenleft}B\ {\isacharbrackleft}{\isacharplus}{\isacharbrackright}\ C{\isacharparenright}}
       
   104   (due to nesting to the left).  We have preferred to give the fully
       
   105   parenthesized form in the text for clarity.  Only in rare situations
       
   106   one may consider to force parentheses by use of non-oriented infix
       
   107   syntax; equality would probably be a typical candidate.%
       
   108 \end{isamarkuptext}%
    90 \end{isamarkuptext}%
   109 \isamarkuptrue%
    91 \isamarkuptrue%
   110 %
    92 %
   111 \isamarkupsubsection{Mathematical Symbols%
    93 \isamarkupsubsection{Mathematical Symbols%
   112 }
    94 }
   115 \begin{isamarkuptext}%
    97 \begin{isamarkuptext}%
   116 Concrete syntax based on plain ASCII characters has its inherent
    98 Concrete syntax based on plain ASCII characters has its inherent
   117   limitations.  Rich mathematical notation demands a larger repertoire
    99   limitations.  Rich mathematical notation demands a larger repertoire
   118   of symbols.  Several standards of extended character sets have been
   100   of symbols.  Several standards of extended character sets have been
   119   proposed over decades, but none has become universally available so
   101   proposed over decades, but none has become universally available so
   120   far, not even Unicode\index{Unicode}.
   102   far, not even Unicode\index{Unicode}.  Isabelle supports a generic
   121 
   103   notion of \bfindex{symbols} as the smallest entities of source text,
   122   Isabelle supports a generic notion of \bfindex{symbols} as the
   104   without referring to internal encodings.
   123   smallest entities of source text, without referring to internal
   105 
   124   encodings.  Such ``generalized characters'' may be of one of the
   106   There are three kinds of such ``generalized characters'' available:
   125   following three kinds:
       
   126 
   107 
   127   \begin{enumerate}
   108   \begin{enumerate}
   128 
   109 
   129   \item Traditional 7-bit ASCII characters.
   110   \item 7-bit ASCII characters
   130 
   111 
   131   \item Named symbols: \verb,\,\verb,<,$ident$\verb,>, (or
   112   \item named symbols: \verb,\,\verb,<,$ident$\verb,>,
   132   \verb,\\,\verb,<,$ident$\verb,>,).
   113 
   133 
   114   \item named control symbols: \verb,\,\verb,<^,$ident$\verb,>,
   134   \item Named control symbols: \verb,\,\verb,<^,$ident$\verb,>, (or
       
   135   \verb,\\,\verb,<^,$ident$\verb,>,).
       
   136 
   115 
   137   \end{enumerate}
   116   \end{enumerate}
   138 
   117 
   139   Here $ident$ may be any identifier according to the usual Isabelle
   118   Here $ident$ may be any identifier according to the usual Isabelle
   140   conventions.  This results in an infinite store of symbols, whose
   119   conventions.  This results in an infinite store of symbols, whose
   141   interpretation is left to further front-end tools.  For example, the
   120   interpretation is left to further front-end tools.  For example,
   142   \verb,\,\verb,<forall>, symbol of Isabelle is really displayed as
   121   both by the user-interface of Proof~General + X-Symbol and the
   143   $\forall$ --- both by the user-interface of Proof~General + X-Symbol
   122   Isabelle document processor (see \S\ref{sec:document-preparation})
   144   and the Isabelle document processor (see \S\ref{sec:document-prep}).
   123   display the \verb,\,\verb,<forall>, symbol really as ``$\forall$''.
   145 
   124 
   146   A list of standard Isabelle symbols is given in
   125   A list of standard Isabelle symbols is given in
   147   \cite[appendix~A]{isabelle-sys}.  Users may introduce their own
   126   \cite[appendix~A]{isabelle-sys}.  Users may introduce their own
   148   interpretation of further symbols by configuring the appropriate
   127   interpretation of further symbols by configuring the appropriate
   149   front-end tool accordingly, e.g.\ defining appropriate {\LaTeX}
   128   front-end tool accordingly, e.g.\ by defining certain {\LaTeX}
   150   macros for document preparation.  There are also a few predefined
   129   macros (see also \S\ref{sec:doc-prep-symbols}).  There are also a
   151   control symbols, such as \verb,\,\verb,<^sub>, and
   130   few predefined control symbols, such as \verb,\,\verb,<^sub>, and
   152   \verb,\,\verb,<^sup>, for sub- and superscript of the subsequent
   131   \verb,\,\verb,<^sup>, for sub- and superscript of the subsequent
   153   (printable) symbol, respectively.
   132   (printable) symbol, respectively.  For example, \verb,A\<^sup>\<star>, is
       
   133   shown as ``\isa{A\isactrlsup {\isasymstar}}''.
   154 
   134 
   155   \medskip The following version of our \isa{xor} definition uses a
   135   \medskip The following version of our \isa{xor} definition uses a
   156   standard Isabelle symbol to achieve typographically pleasing output.%
   136   standard Isabelle symbol to achieve typographically pleasing output.%
   157 \end{isamarkuptext}%
   137 \end{isamarkuptext}%
   158 \isamarkuptrue%
   138 \isamarkuptrue%
   162 \ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymoplus}{\isachardoublequote}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isanewline
   142 \ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymoplus}{\isachardoublequote}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isanewline
   163 \ \ {\isachardoublequote}A\ {\isasymoplus}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
   143 \ \ {\isachardoublequote}A\ {\isasymoplus}\ B\ {\isasymequiv}\ {\isacharparenleft}A\ {\isasymand}\ {\isasymnot}\ B{\isacharparenright}\ {\isasymor}\ {\isacharparenleft}{\isasymnot}\ A\ {\isasymand}\ B{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
   164 \isamarkupfalse%
   144 \isamarkupfalse%
   165 %
   145 %
   166 \begin{isamarkuptext}%
   146 \begin{isamarkuptext}%
   167 The X-Symbol package within Proof~General provides several input
   147 \noindent The X-Symbol package within Proof~General provides several
   168   methods to enter \isa{{\isasymoplus}} in the text.  If all fails one may just
   148   input methods to enter \isa{{\isasymoplus}} in the text.  If all fails one may
   169   type \verb,\,\verb,<oplus>, by hand; the display is adapted
   149   just type \verb,\,\verb,<oplus>, by hand; the display will be
   170   immediately after continuing further input.
   150   adapted immediately after continuing input.
   171 
   151 
   172   \medskip A slightly more refined scheme is to provide alternative
   152   \medskip A slightly more refined scheme is to provide alternative
   173   syntax via the \bfindex{print mode} concept of Isabelle (see also
   153   syntax via the \bfindex{print mode} concept of Isabelle (see also
   174   \cite{isabelle-ref}).  By convention, the mode ``$xsymbols$'' is
   154   \cite{isabelle-ref}).  By convention, the mode of ``$xsymbols$'' is
   175   enabled whenever X-Symbol is active.  Consider the following hybrid
   155   enabled whenever Proof~General's X-Symbol mode (or {\LaTeX} output)
   176   declaration of \isa{xor}.%
   156   is active.  Consider the following hybrid declaration of \isa{xor}.%
   177 \end{isamarkuptext}%
   157 \end{isamarkuptext}%
   178 \isamarkuptrue%
   158 \isamarkuptrue%
   179 \isamarkupfalse%
   159 \isamarkupfalse%
   180 \isamarkupfalse%
   160 \isamarkupfalse%
   181 \isacommand{constdefs}\isanewline
   161 \isacommand{constdefs}\isanewline
   186 \isacommand{syntax}\ {\isacharparenleft}xsymbols{\isacharparenright}\isanewline
   166 \isacommand{syntax}\ {\isacharparenleft}xsymbols{\isacharparenright}\isanewline
   187 \ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymoplus}{\isasymignore}{\isachardoublequote}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isamarkupfalse%
   167 \ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymoplus}{\isasymignore}{\isachardoublequote}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isamarkupfalse%
   188 \isamarkupfalse%
   168 \isamarkupfalse%
   189 %
   169 %
   190 \begin{isamarkuptext}%
   170 \begin{isamarkuptext}%
   191 Here the \commdx{syntax} command acts like \isakeyword{consts}, but
   171 The \commdx{syntax} command introduced here acts like
   192   without declaring a logical constant, and with an optional print
   172   \isakeyword{consts}, but without declaring a logical constant; an
   193   mode specification.  Note that the type declaration given here
   173   optional print mode specification may be given, too.  Note that the
   194   merely serves for syntactic purposes, and is not checked for
   174   type declaration given here merely serves for syntactic purposes,
   195   consistency with the real constant.
   175   and is not checked for consistency with the real constant.
   196 
   176 
   197   \medskip Now we may write either \isa{{\isacharbrackleft}{\isacharplus}{\isacharbrackright}} or \isa{{\isasymoplus}} in
   177   \medskip We may now write either \isa{{\isacharbrackleft}{\isacharplus}{\isacharbrackright}} or \isa{{\isasymoplus}} in
   198   input, while output uses the nicer syntax of $xsymbols$, provided
   178   input, while output uses the nicer syntax of $xsymbols$, provided
   199   that print mode is presently active.  This scheme is particularly
   179   that print mode is presently active.  Such an arrangement is
   200   useful for interactive development, with the user typing plain ASCII
   180   particularly useful for interactive development, where users may
   201   text, but gaining improved visual feedback from the system (say in
   181   type plain ASCII text, but gain improved visual feedback from the
   202   current goal output).
   182   system (say in current goal output).
   203 
   183 
   204   \begin{warn}
   184   \begin{warn}
   205   Using alternative syntax declarations easily results in varying
   185   Alternative syntax declarations are apt to result in varying
   206   versions of input sources.  Isabelle provides no systematic way to
   186   occurrences of concrete syntax in the input sources.  Isabelle
   207   convert alternative expressions back and forth.  Print modes only
   187   provides no systematic way to convert alternative syntax expressions
   208   affect situations where formal entities are pretty printed by the
   188   back and forth; print modes only affect situations where formal
   209   Isabelle process (e.g.\ output of terms and types), but not the
   189   entities are pretty printed by the Isabelle process (e.g.\ output of
   210   original theory text.
   190   terms and types), but not the original theory text.
   211   \end{warn}
   191   \end{warn}
   212 
   192 
   213   \medskip The following variant makes the alternative \isa{{\isasymoplus}}
   193   \medskip The following variant makes the alternative \isa{{\isasymoplus}}
   214   notation only available for output.  Thus we may enforce input
   194   notation only available for output.  Thus we may enforce input
   215   sources to refer to plain ASCII only.%
   195   sources to refer to plain ASCII only, but effectively disable
       
   196   cut-and-paste from output as well.%
   216 \end{isamarkuptext}%
   197 \end{isamarkuptext}%
   217 \isamarkuptrue%
   198 \isamarkuptrue%
   218 \isacommand{syntax}\ {\isacharparenleft}xsymbols\ \isakeyword{output}{\isacharparenright}\isanewline
   199 \isacommand{syntax}\ {\isacharparenleft}xsymbols\ \isakeyword{output}{\isacharparenright}\isanewline
   219 \ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymoplus}{\isasymignore}{\isachardoublequote}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isamarkupfalse%
   200 \ \ xor\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}bool\ {\isasymRightarrow}\ bool\ {\isasymRightarrow}\ bool{\isachardoublequote}\ \ \ \ {\isacharparenleft}\isakeyword{infixl}\ {\isachardoublequote}{\isasymoplus}{\isasymignore}{\isachardoublequote}\ {\isadigit{6}}{\isadigit{0}}{\isacharparenright}\isamarkupfalse%
   220 %
   201 %
   221 \isamarkupsubsection{Prefix Annotations%
   202 \isamarkupsubsection{Prefix Annotations%
   222 }
   203 }
   223 \isamarkuptrue%
   204 \isamarkuptrue%
   224 %
   205 %
   225 \begin{isamarkuptext}%
   206 \begin{isamarkuptext}%
   226 Prefix syntax annotations\index{prefix annotation} are just a very
   207 Prefix syntax annotations\index{prefix annotation} are just another
   227   degenerate of the general mixfix form \cite{isabelle-ref}, without
   208   degenerate form of general mixfixes \cite{isabelle-ref}, without any
   228   any template arguments or priorities --- just some piece of literal
   209   template arguments or priorities --- just some bits of literal
   229   syntax.
   210   syntax.  The following example illustrates this idea idea by
   230 
   211   associating common symbols with the constructors of a datatype.%
   231   The following example illustrates this idea idea by associating
       
   232   common symbols with the constructors of a currency datatype.%
       
   233 \end{isamarkuptext}%
   212 \end{isamarkuptext}%
   234 \isamarkuptrue%
   213 \isamarkuptrue%
   235 \isacommand{datatype}\ currency\ {\isacharequal}\isanewline
   214 \isacommand{datatype}\ currency\ {\isacharequal}\isanewline
   236 \ \ \ \ Euro\ nat\ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isasymeuro}{\isachardoublequote}{\isacharparenright}\isanewline
   215 \ \ \ \ Euro\ nat\ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isasymeuro}{\isachardoublequote}{\isacharparenright}\isanewline
   237 \ \ {\isacharbar}\ Pounds\ nat\ \ {\isacharparenleft}{\isachardoublequote}{\isasympounds}{\isachardoublequote}{\isacharparenright}\isanewline
   216 \ \ {\isacharbar}\ Pounds\ nat\ \ {\isacharparenleft}{\isachardoublequote}{\isasympounds}{\isachardoublequote}{\isacharparenright}\isanewline
   238 \ \ {\isacharbar}\ Yen\ nat\ \ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isasymyen}{\isachardoublequote}{\isacharparenright}\isanewline
   217 \ \ {\isacharbar}\ Yen\ nat\ \ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isasymyen}{\isachardoublequote}{\isacharparenright}\isanewline
   239 \ \ {\isacharbar}\ Dollar\ nat\ \ {\isacharparenleft}{\isachardoublequote}{\isachardollar}{\isachardoublequote}{\isacharparenright}\isamarkupfalse%
   218 \ \ {\isacharbar}\ Dollar\ nat\ \ {\isacharparenleft}{\isachardoublequote}{\isachardollar}{\isachardoublequote}{\isacharparenright}\isamarkupfalse%
   240 %
   219 %
   241 \begin{isamarkuptext}%
   220 \begin{isamarkuptext}%
   242 \noindent Here the degenerate mixfix annotations on the rightmost
   221 \noindent Here the mixfix annotations on the rightmost column happen
   243   column happen to consist of a single Isabelle symbol each:
   222   to consist of a single Isabelle symbol each: \verb,\,\verb,<euro>,,
   244   \verb,\,\verb,<euro>,, \verb,\,\verb,<pounds>,,
   223   \verb,\,\verb,<pounds>,, \verb,\,\verb,<yen>,, and \verb,$,.  Recall
   245   \verb,\,\verb,<yen>,, and \verb,$,.
   224   that a constructor like \isa{Euro} actually is a function \isa{nat\ {\isasymRightarrow}\ currency}.  An expression like \isa{Euro\ {\isadigit{1}}{\isadigit{0}}} will be
   246 
   225   printed as \isa{{\isasymeuro}\ {\isadigit{1}}{\isadigit{0}}}; only the head of the application is
   247   Recall that a constructor like \isa{Euro} actually is a function
       
   248   \isa{nat\ {\isasymRightarrow}\ currency}.  An expression like \isa{Euro\ {\isadigit{1}}{\isadigit{0}}} will
       
   249   be printed as \isa{{\isasymeuro}\ {\isadigit{1}}{\isadigit{0}}}; only the head of the application is
       
   250   subject to our concrete syntax.  This simple form already achieves
   226   subject to our concrete syntax.  This simple form already achieves
   251   conformance with notational standards of the European Commission.
   227   conformance with notational standards of the European Commission.
   252 
   228 
   253   \medskip Certainly, the same idea of prefix syntax also works for
   229   \medskip Certainly, the same idea of prefix syntax also works for
   254   \isakeyword{consts}, \isakeyword{constdefs} etc.  The slightly
   230   \isakeyword{consts}, \isakeyword{constdefs} etc.  The slightly
   259 \isacommand{syntax}\isanewline
   235 \isacommand{syntax}\isanewline
   260 \ \ currency\ {\isacharcolon}{\isacharcolon}\ type\ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isasymcurrency}{\isachardoublequote}{\isacharparenright}\isamarkupfalse%
   236 \ \ currency\ {\isacharcolon}{\isacharcolon}\ type\ \ \ \ {\isacharparenleft}{\isachardoublequote}{\isasymcurrency}{\isachardoublequote}{\isacharparenright}\isamarkupfalse%
   261 %
   237 %
   262 \begin{isamarkuptext}%
   238 \begin{isamarkuptext}%
   263 \noindent Here \isa{type} refers to the builtin syntactic category
   239 \noindent Here \isa{type} refers to the builtin syntactic category
   264   of Isabelle types.  We could now write down funny things like \isa{{\isasymeuro}\ {\isacharcolon}{\isacharcolon}\ nat\ {\isasymRightarrow}\ {\isasymcurrency}}, for example.%
   240   of Isabelle types.  We may now write down funny things like \isa{{\isasymeuro}\ {\isacharcolon}{\isacharcolon}\ nat\ {\isasymRightarrow}\ {\isasymcurrency}}, for example.%
   265 \end{isamarkuptext}%
   241 \end{isamarkuptext}%
   266 \isamarkuptrue%
   242 \isamarkuptrue%
   267 %
   243 %
   268 \isamarkupsubsection{Syntax Translations \label{sec:syntax-translations}%
   244 \isamarkupsubsection{Syntax Translations \label{sec:syntax-translations}%
   269 }
   245 }
   270 \isamarkuptrue%
   246 \isamarkuptrue%
   271 %
   247 %
   272 \begin{isamarkuptext}%
   248 \begin{isamarkuptext}%
   273 Mixfix syntax annotations work well for those situations, where a
   249 Mixfix syntax annotations work well for those situations where a
   274   constant application forms needs to be decorated by concrete syntax.
   250   particular constant application forms need to be decorated by
   275   Just reconsider \isa{xor\ A\ B} versus \isa{A\ {\isasymoplus}\ B} covered
   251   concrete syntax; just reconsider \isa{xor\ A\ B} versus \isa{A\ {\isasymoplus}\ B} covered before.  Occasionally, the relationship between some
   276   before.  Occasionally, the relationship between some piece of
   252   piece of notation and its internal form is slightly more involved.
   277   notation and its internal form is slightly more involved.
       
   278 
       
   279   Here the concept of \bfindex{syntax translations} enters the scene.
   253   Here the concept of \bfindex{syntax translations} enters the scene.
       
   254 
   280   Using the raw \isakeyword{syntax}\index{syntax (command)} command we
   255   Using the raw \isakeyword{syntax}\index{syntax (command)} command we
   281   introduce uninterpreted notational elements, while
   256   may introduce uninterpreted notational elements, while
   282   \commdx{translations} relates the input forms with certain logical
   257   \commdx{translations} relates the input forms with more complex
   283   expressions.  This essentially provides a simple mechanism for for
   258   logical expressions.  This essentially provides a simple mechanism
   284   syntactic macros; even heavier transformations may be programmed in
   259   for for syntactic macros; even heavier transformations may be
   285   ML \cite{isabelle-ref}.
   260   programmed in ML \cite{isabelle-ref}.
   286 
   261 
   287   \medskip A typical example of syntax translations is to decorate an
   262   \medskip A typical example of syntax translations is to decorate
   288   relational expression (i.e.\ set membership of tuples) with nice
   263   relational expressions (set membership of tuples) with nice symbolic
   289   symbolic notation, such as \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim} versus \isa{x\ {\isasymapprox}\ y}.%
   264   notation, such as \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim} versus \isa{x\ {\isasymapprox}\ y}.%
   290 \end{isamarkuptext}%
   265 \end{isamarkuptext}%
   291 \isamarkuptrue%
   266 \isamarkuptrue%
   292 \isacommand{consts}\isanewline
   267 \isacommand{consts}\isanewline
   293 \ \ sim\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a{\isacharparenright}\ set{\isachardoublequote}\isanewline
   268 \ \ sim\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequote}{\isacharparenleft}{\isacharprime}a\ {\isasymtimes}\ {\isacharprime}a{\isacharparenright}\ set{\isachardoublequote}\isanewline
   294 \isanewline
   269 \isanewline
   299 \isacommand{translations}\isanewline
   274 \isacommand{translations}\isanewline
   300 \ \ {\isachardoublequote}x\ {\isasymapprox}\ y{\isachardoublequote}\ {\isasymrightleftharpoons}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim{\isachardoublequote}\isamarkupfalse%
   275 \ \ {\isachardoublequote}x\ {\isasymapprox}\ y{\isachardoublequote}\ {\isasymrightleftharpoons}\ {\isachardoublequote}{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim{\isachardoublequote}\isamarkupfalse%
   301 %
   276 %
   302 \begin{isamarkuptext}%
   277 \begin{isamarkuptext}%
   303 \noindent Here the name of the dummy constant \isa{{\isacharunderscore}sim} does
   278 \noindent Here the name of the dummy constant \isa{{\isacharunderscore}sim} does
   304   not really matter, as long as it is not used otherwise.  Prefixing
   279   not really matter, as long as it is not used elsewhere.  Prefixing
   305   an underscore is a common convention.  The \isakeyword{translations}
   280   an underscore is a common convention.  The \isakeyword{translations}
   306   declaration already uses concrete syntax on the left-hand side;
   281   declaration already uses concrete syntax on the left-hand side;
   307   internally we relate a raw application \isa{{\isacharunderscore}sim\ x\ y} with
   282   internally we relate a raw application \isa{{\isacharunderscore}sim\ x\ y} with
   308   \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim}.
   283   \isa{{\isacharparenleft}x{\isacharcomma}\ y{\isacharparenright}\ {\isasymin}\ sim}.
   309 
   284 
   310   \medskip Another useful application of syntax translations is to
   285   \medskip Another common application of syntax translations is to
   311   provide variant versions of fundamental relational expressions, such
   286   provide variant versions of fundamental relational expressions, such
   312   as \isa{{\isasymnoteq}} for negated equalities.  The following declaration
   287   as \isa{{\isasymnoteq}} for negated equalities.  The following declaration
   313   stems from Isabelle/HOL itself:%
   288   stems from Isabelle/HOL itself:%
   314 \end{isamarkuptext}%
   289 \end{isamarkuptext}%
   315 \isamarkuptrue%
   290 \isamarkuptrue%
   317 \isamarkupfalse%
   292 \isamarkupfalse%
   318 \isacommand{translations}\ {\isachardoublequote}x\ {\isasymnoteq}{\isasymignore}\ y{\isachardoublequote}\ {\isasymrightleftharpoons}\ {\isachardoublequote}{\isasymnot}\ {\isacharparenleft}x\ {\isacharequal}\ y{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
   293 \isacommand{translations}\ {\isachardoublequote}x\ {\isasymnoteq}{\isasymignore}\ y{\isachardoublequote}\ {\isasymrightleftharpoons}\ {\isachardoublequote}{\isasymnot}\ {\isacharparenleft}x\ {\isacharequal}\ y{\isacharparenright}{\isachardoublequote}\isamarkupfalse%
   319 %
   294 %
   320 \begin{isamarkuptext}%
   295 \begin{isamarkuptext}%
   321 \noindent Normally one would introduce derived concepts like this
   296 \noindent Normally one would introduce derived concepts like this
   322   within the logic, using \isakeyword{consts} and \isakeyword{defs}
   297   within the logic, using \isakeyword{consts} + \isakeyword{defs}
   323   instead of \isakeyword{syntax} and \isakeyword{translations}.  The
   298   instead of \isakeyword{syntax} + \isakeyword{translations}.  The
   324   present formulation has the virtue that expressions are immediately
   299   present formulation has the virtue that expressions are immediately
   325   replaced by its ``definition'' upon parsing; the effect is reversed
   300   replaced by its ``definition'' upon parsing; the effect is reversed
   326   upon printing.  Internally, \isa{{\isasymnoteq}} never appears.
   301   upon printing.  Internally, \isa{{\isasymnoteq}} never appears.
   327 
   302 
   328   Simulating definitions via translations is adequate for very basic
   303   Simulating definitions via translations is adequate for very basic
   329   variations of fundamental logical concepts, when the new
   304   logical concepts, where a new representation is a trivial variation
   330   representation is a trivial variation on an existing one.  On the
   305   on an existing one.  On the other hand, syntax translations do not
   331   other hand, syntax translations do not scale up well to large
   306   scale up well to large hierarchies of concepts built on each other.%
   332   hierarchies of concepts built on each other.%
   307 \end{isamarkuptext}%
   333 \end{isamarkuptext}%
   308 \isamarkuptrue%
   334 \isamarkuptrue%
   309 %
   335 %
   310 \isamarkupsection{Document Preparation \label{sec:document-preparation}%
   336 \isamarkupsection{Document Preparation \label{sec:document-prep}%
   311 }
   337 }
   312 \isamarkuptrue%
   338 \isamarkuptrue%
   313 %
   339 %
   314 \begin{isamarkuptext}%
   340 \begin{isamarkuptext}%
   315 Isabelle/Isar is centered around the concept of \bfindex{formal
   341 Isabelle/Isar is centered around a certain notion of \bfindex{formal
   316   proof documents}\index{documents|bold}.  Ultimately the result of
   342   proof documents}\index{documents|bold}: ultimately the result of the
   317   the user's theory development efforts is meant to be a
   343   user's theory development efforts is a human-readable record --- as
   318   human-readable record, presented as a browsable PDF file or printed
   344   a browsable PDF file or printed on paper.  The overall document
   319   on paper.  The overall document structure follows traditional
   345   structure follows traditional mathematical articles, with
   320   mathematical articles, with sectioning, intermediate explanations,
   346   sectioning, explanations, definitions, theorem statements, and
   321   definitions, theorem statements and proofs.
   347   proofs.
       
   348 
   322 
   349   The Isar proof language \cite{Wenzel-PhD}, which is not covered in
   323   The Isar proof language \cite{Wenzel-PhD}, which is not covered in
   350   this book, admits to write formal proof texts that are acceptable
   324   this book, admits to write formal proof texts that are acceptable
   351   both to the machine and human readers at the same time.  Thus
   325   both to the machine and human readers at the same time.  Thus
   352   marginal comments and explanations may be kept at a minimum.
   326   marginal comments and explanations may be kept at a minimum.  Even
   353   Nevertheless, Isabelle document output is still useful without
   327   without proper coverage of human-readable proofs, Isabelle document
   354   actual Isar proof texts; formal specifications usually deserve their
   328   is very useful to produce formally derived texts (elaborating on the
   355   own coverage in the text, while unstructured proof scripts may be
   329   specifications etc.).  Unstructured proof scripts given here may be
   356   just ignore by readers (or intentionally suppressed from the text).
   330   just ignored by readers, or intentionally suppressed from the text
       
   331   by the writer (see also \S\ref{sec:doc-prep-suppress}).
   357 
   332 
   358   \medskip The Isabelle document preparation system essentially acts
   333   \medskip The Isabelle document preparation system essentially acts
   359   like a formal front-end for {\LaTeX}.  After checking definitions
   334   like a formal front-end to {\LaTeX}.  After checking specifications
   360   and proofs the theory sources are turned into typesetting
   335   and proofs, the theory sources are turned into typesetting
   361   instructions, so the final document is known to observe quite strong
   336   instructions in a well-defined manner.  This enables users to write
   362   ``soundness'' properties.  This enables users to write authentic
   337   authentic reports on formal theory developments with little
   363   reports on formal theory developments with little additional effort,
   338   additional effort, the most tedious consistency checks are handled
   364   the most tedious consistency checks are handled by the system.%
   339   by the system.%
   365 \end{isamarkuptext}%
   340 \end{isamarkuptext}%
   366 \isamarkuptrue%
   341 \isamarkuptrue%
   367 %
   342 %
   368 \isamarkupsubsection{Isabelle Sessions%
   343 \isamarkupsubsection{Isabelle Sessions%
   369 }
   344 }
   370 \isamarkuptrue%
   345 \isamarkuptrue%
   371 %
   346 %
   372 \begin{isamarkuptext}%
   347 \begin{isamarkuptext}%
   373 In contrast to the highly interactive mode of the formal parts of
   348 In contrast to the highly interactive mode of Isabelle/Isar theory
   374   Isabelle/Isar theory development, the document preparation stage
   349   development, the document preparation stage essentially works in
   375   essentially works in batch-mode.  This revolves around the concept
   350   batch-mode.  An Isabelle \bfindex{session} essentially consists of a
   376   of a \bfindex{session}, which essentially consists of a collection
   351   collection of theory source files that contribute to a single output
   377   of theory source files that contribute to a single output document.
   352   document eventually.  Session is derived from a single parent each
   378   Each session is derived from a parent one (usually an object-logic
   353   (usually an object-logic image like \texttt{HOL}), resulting in an
   379   image such as \texttt{HOL}); this results in an overall tree
   354   overall tree structure that is reflected in the output location
   380   structure of Isabelle sessions.
   355   within the file system (usually rooted at
   381 
   356   \verb,~/isabelle/browser_info,).
   382   The canonical arrangement of source files of a session called
   357 
   383   \texttt{MySession} is as follows:
   358   Here is the canonical arrangement of sources of a session called
       
   359   \texttt{MySession}:
   384 
   360 
   385   \begin{itemize}
   361   \begin{itemize}
   386 
   362 
   387   \item Directory \texttt{MySession} contains the required theory
   363   \item Directory \texttt{MySession} contains the required theory
   388   files, say $A@1$\texttt{.thy}, \dots, $A@n$\texttt{.thy}.
   364   files ($A@1$\texttt{.thy}, \dots, $A@n$\texttt{.thy}).
   389 
   365 
   390   \item File \texttt{MySession/ROOT.ML} holds appropriate ML commands
   366   \item File \texttt{MySession/ROOT.ML} holds appropriate ML commands
   391   for loading all wanted theories, usually just
   367   for loading all wanted theories, usually just
   392   \texttt{use_thy~"$A@i$"} for any $A@i$ in leaf position of the
   368   ``\texttt{use_thy~"$A@i$";}'' for any $A@i$ in leaf position of the
   393   theory dependency graph.
   369   theory dependency graph.
   394 
   370 
   395   \item Directory \texttt{MySession/document} contains everything
   371   \item Directory \texttt{MySession/document} contains everything
   396   required for the {\LaTeX} stage, but only \texttt{root.tex} needs to
   372   required for the {\LaTeX} stage; only \texttt{root.tex} needs to be
   397   be provided initially.  The latter file holds appropriate {\LaTeX}
   373   provided initially.
   398   code to commence a document (\verb,\documentclass, etc.), and to
   374 
   399   include the generated files $A@i$\texttt{.tex} for each theory.  The
   375   The latter file holds appropriate {\LaTeX} code to commence a
   400   generated file \texttt{session.tex} holds {\LaTeX} commands to
   376   document (\verb,\documentclass, etc.), and to include the generated
   401   include \emph{all} theory output files in topologically sorted
   377   files $A@i$\texttt{.tex} for each theory.  The generated
   402   order.
   378   \texttt{session.tex} will hold {\LaTeX} commands to include all
   403 
   379   theory output files in topologically sorted order, so
   404   \item In addition an \texttt{IsaMakefile} outside of directory
   380   \verb,\input{session}, in \texttt{root.tex} will do it in most
       
   381   situations.
       
   382 
       
   383   \item In addition, \texttt{IsaMakefile} outside of the directory
   405   \texttt{MySession} holds appropriate dependencies and invocations of
   384   \texttt{MySession} holds appropriate dependencies and invocations of
   406   Isabelle tools to control the batch job.  The details are covered in
   385   Isabelle tools to control the batch job.  In fact, several sessions
   407   \cite{isabelle-sys}; \texttt{isatool usedir} is the most important
   386   may be controlled by the same \texttt{IsaMakefile}.  See also
   408   entry point.
   387   \cite{isabelle-sys} for further details, especially on
       
   388   \texttt{isatool usedir} and \texttt{isatool make}.
   409 
   389 
   410   \end{itemize}
   390   \end{itemize}
   411 
   391 
   412   With everything put in its proper place, \texttt{isatool make}
   392   With everything put in its proper place, \texttt{isatool make}
   413   should be sufficient to process the Isabelle session completely,
   393   should be sufficient to process the Isabelle session completely,
   414   with the generated document appearing in its proper place (within
   394   with the generated document appearing in its proper place.
   415   \verb,~/isabelle/browser_info,).
   395 
   416 
   396   \medskip In practice, users may want to have \texttt{isatool mkdir}
   417   In practice, users may want to have \texttt{isatool mkdir} generate
   397   generate an initial working setup without further ado.  For example,
   418   an initial working setup without further ado.  For example, an empty
   398   an empty session \texttt{MySession} derived from \texttt{HOL} may be
   419   session \texttt{MySession} derived from \texttt{HOL} may be produced
   399   produced as follows:
   420   as follows:
       
   421 
   400 
   422 \begin{verbatim}
   401 \begin{verbatim}
   423   isatool mkdir HOL MySession
   402   isatool mkdir HOL MySession
   424   isatool make
   403   isatool make
   425 \end{verbatim}
   404 \end{verbatim}
   426 
   405 
   427   This runs the session with sensible default options, including
   406   This processes the session with sensible default options, including
   428   verbose mode to tell the user where the result will appear.  The
   407   verbose mode to tell the user where the ultimate results will
   429   above dry run should produce should produce a single page of output
   408   appear.  The above dry run should produce should already be able to
   430   (with a dummy title, empty table of contents etc.).  Any failure at
   409   produce a single page of output (with a dummy title, empty table of
   431   that stage is likely to indicate some technical problems with your
   410   contents etc.).  Any failure at that stage is likely to indicate
   432   {\LaTeX} installation.\footnote{Especially make sure that
   411   technical problems with the user's {\LaTeX}
   433   \texttt{pdflatex} is present.}
   412   installation.\footnote{Especially make sure that \texttt{pdflatex}
   434 
   413   is present; if all fails one may fall back on DVI output by changing
   435   \medskip Users may now start to populate the directory
   414   \texttt{usedir} options \cite{isabelle-sys}.}
       
   415 
       
   416   \medskip One may now start to populate the directory
   436   \texttt{MySession}, and the file \texttt{MySession/ROOT.ML}
   417   \texttt{MySession}, and the file \texttt{MySession/ROOT.ML}
   437   accordingly.  \texttt{MySession/document/root.tex} should be also
   418   accordingly.  \texttt{MySession/document/root.tex} should be also
   438   adapted at some point; the generated version is mostly
   419   adapted at some point; the default version is mostly
   439   self-explanatory.  The default versions includes the
   420   self-explanatory.
   440   \texttt{isabelle} (mandatory) and \texttt{isabellesym} (required for
   421 
   441   mathematical symbols); further packages may required, e.g.\ for
   422   Especially note the standard inclusion of {\LaTeX} packages
   442   unusual Isabelle symbols.
   423   \texttt{isabelle} (mandatory), and \texttt{isabellesym} (required
   443 
   424   for mathematical symbols), and the final \texttt{pdfsetup} (provides
   444   Realistic applications may demand additional files in
   425   handsome defaults for \texttt{hyperref}, including URL markup).
   445   \texttt{MySession/document} for the {\LaTeX} stage, such as
   426   Further {\LaTeX} packages further packages may required in
   446   \texttt{root.bib} for the bibliographic database.\footnote{Using
   427   particular applications, e.g.\ for unusual Isabelle symbols.
   447   that particular name of \texttt{root.bib}, the Isabelle document
   428 
   448   processor (actually \texttt{isatool document} \cite{isabelle-sys})
   429   \medskip Further auxiliary files for the {\LaTeX} stage should be
   449   will be smart enough to invoke \texttt{bibtex} accordingly.}
   430   included in the \texttt{MySession/document} directory, e.g.\
   450 
   431   additional {\TeX} sources or graphics.  In particular, adding
   451   \medskip Failure of the document preparation phase in an Isabelle
   432   \texttt{root.bib} here (with that specific name) causes an automatic
   452   batch session leaves the generated sources in there target location
   433   run of \texttt{bibtex} to process a bibliographic database; see for
   453   (as pointed out by the accompanied error message).  In case of
   434   further commodities \texttt{isatool document} covered in
   454   {\LaTeX} errors, users may trace error messages at the file position
   435   \cite{isabelle-sys}.
   455   of the generated text.%
   436 
       
   437   \medskip Any failure of the document preparation phase in an
       
   438   Isabelle batch session leaves the generated sources in there target
       
   439   location (as pointed out by the accompanied error message).  In case
       
   440   of {\LaTeX} errors, users may trace error messages at the file
       
   441   position of the generated text.%
   456 \end{isamarkuptext}%
   442 \end{isamarkuptext}%
   457 \isamarkuptrue%
   443 \isamarkuptrue%
   458 %
   444 %
   459 \isamarkupsubsection{Structure Markup%
   445 \isamarkupsubsection{Structure Markup%
   460 }
   446 }
   461 \isamarkuptrue%
   447 \isamarkuptrue%
   462 %
   448 %
   463 \isamarkupsubsubsection{Sections%
   449 \begin{isamarkuptext}%
   464 }
   450 The large-scale structure of Isabelle documents follows existing
   465 \isamarkuptrue%
   451   {\LaTeX} conventions, with chapters, sections, subsubsections etc.
   466 %
   452   The Isar language includes separate \bfindex{markup commands}, which
   467 \begin{isamarkuptext}%
   453   do not effect the formal content of a theory (or proof), but result
   468 The large-scale structure of Isabelle documents closely follows
   454   in corresponding {\LaTeX} elements issued to the output.
   469   {\LaTeX} convention, with chapters, sections, subsubsections etc.
   455 
   470   The formal Isar language includes separate structure \bfindex{markup
   456   There are separate markup commands for different formal contexts: in
   471   commands}, which do not effect the formal content of a theory (or
   457   header position (just before a \isakeyword{theory} command), within
   472   proof), but results in corresponding {\LaTeX} elements issued to the
   458   the theory body, or within a proof.  Note that the header needs to
   473   output.
   459   be treated specially, since ordinary theory and proof commands may
   474 
   460   only occur \emph{after} the initial \isakeyword{theory}
   475   There are different markup commands for different formal contexts:
       
   476   in header position (just before a \isakeyword{theory} command),
       
   477   within the theory body, or within a proof.  Note that the header
       
   478   needs to be treated specially, since ordinary theory and proof
       
   479   commands may only occur \emph{after} the initial \isakeyword{theory}
       
   480   specification.
   461   specification.
   481 
   462 
   482   \smallskip
   463   \smallskip
   483 
   464 
   484   \begin{tabular}{llll}
   465   \begin{tabular}{llll}
   491 
   472 
   492   \medskip
   473   \medskip
   493 
   474 
   494   From the Isabelle perspective, each markup command takes a single
   475   From the Isabelle perspective, each markup command takes a single
   495   text argument (delimited by \verb,",\dots\verb,", or
   476   text argument (delimited by \verb,",\dots\verb,", or
   496   \verb,{,\verb,*,~\dots~\verb,*,\verb,},).  After stripping
   477   \verb,{,\verb,*,~\dots~\verb,*,\verb,},).  After stripping any
   497   surrounding white space, the argument is passed to a {\LaTeX} macro
   478   surrounding white space, the argument is passed to a {\LaTeX} macro
   498   \verb,\isamarkupXXX, for any command \isakeyword{XXX}.  The latter
   479   \verb,\isamarkupXYZ, for any command \isakeyword{XYZ}.  These macros
   499   are defined in \verb,isabelle.sty, according to the rightmost column
   480   are defined in \verb,isabelle.sty, according to the meaning given in
   500   above.
   481   the rightmost column above.
   501 
   482 
   502   \medskip The following source fragment illustrates structure markup
   483   \medskip The following source fragment illustrates structure markup
   503   of a theory.  Note that {\LaTeX} labels may well be included inside
   484   of a theory.  Note that {\LaTeX} labels may be included inside of
   504   of section headings as well.
   485   section headings as well.
   505 
   486 
   506   \begin{ttbox}
   487   \begin{ttbox}
   507   header {\ttlbrace}* Some properties of Foo Bar elements *{\ttrbrace}
   488   header {\ttlbrace}* Some properties of Foo Bar elements *{\ttrbrace}
   508 
   489 
   509   theory Foo_Bar = Main:
   490   theory Foo_Bar = Main:
   526   theorem main: \dots
   507   theorem main: \dots
   527 
   508 
   528   end
   509   end
   529   \end{ttbox}
   510   \end{ttbox}
   530 
   511 
   531   Users may occasionally want to change the meaning of some markup
   512   Users may occasionally want to change the meaning of markup
   532   commands, typically via appropriate use of \verb,\renewcommand, in
   513   commands, say via \verb,\renewcommand, in \texttt{root.tex}.  The
   533   \texttt{root.tex}.  The \verb,\isamarkupheader, is a good candidate
   514   \verb,\isamarkupheader, is a good candidate for some adaption, e.g.\
   534   for some adaption, e.g.\ moving it up in the hierarchy to become
   515   moving it up in the hierarchy to become \verb,\chapter,.
   535   \verb,\chapter,.
       
   536 
   516 
   537 \begin{verbatim}
   517 \begin{verbatim}
   538   \renewcommand{\isamarkupheader}[1]{\chapter{#1}}
   518   \renewcommand{\isamarkupheader}[1]{\chapter{#1}}
   539 \end{verbatim}
   519 \end{verbatim}
   540 
   520 
   541   Certainly, this requires to change the default
   521   \noindent Certainly, this requires to change the default
   542   \verb,\documentclass{article}, in \texttt{root.tex} to something
   522   \verb,\documentclass{article}, in \texttt{root.tex} to something
   543   that supports the notion of chapters in the first place, e.g.\
   523   that supports the notion of chapters in the first place, e.g.\
   544   \verb,\documentclass{report},.
   524   \verb,\documentclass{report},.
   545 
   525 
   546   \medskip The {\LaTeX} macro \verb,\isabellecontext, is maintained to
   526   \medskip The {\LaTeX} macro \verb,\isabellecontext, is maintained to
   547   hold the name of the current theory context.  This is particularly
   527   hold the name of the current theory context.  This is particularly
   548   useful for document headings or footings, e.g.\ like this:
   528   useful for document headings:
   549 
   529 
   550 \begin{verbatim}
   530 \begin{verbatim}
   551   \renewcommand{\isamarkupheader}[1]%
   531   \renewcommand{\isamarkupheader}[1]
   552   {\chapter{#1}\markright{THEORY~\isabellecontext}}
   532   {\chapter{#1}\markright{THEORY~\isabellecontext}}
   553 \end{verbatim}
   533 \end{verbatim}
   554 
   534 
   555   \noindent Make sure to include something like
   535   \noindent Make sure to include something like
   556   \verb,\pagestyle{headings}, in \texttt{root.tex}; the document
   536   \verb,\pagestyle{headings}, in \texttt{root.tex}; the document
   567 
   547 
   568   FIXME%
   548   FIXME%
   569 \end{isamarkuptext}%
   549 \end{isamarkuptext}%
   570 \isamarkuptrue%
   550 \isamarkuptrue%
   571 %
   551 %
   572 \isamarkupsubsection{Symbols and Characters%
   552 \isamarkupsubsection{Symbols and Characters \label{sec:doc-prep-symbols}%
   573 }
   553 }
   574 \isamarkuptrue%
   554 \isamarkuptrue%
   575 %
   555 %
   576 \begin{isamarkuptext}%
   556 \begin{isamarkuptext}%
   577 FIXME \verb,\isabellestyle,%
   557 FIXME \verb,\isabellestyle,%
   578 \end{isamarkuptext}%
   558 \end{isamarkuptext}%
   579 \isamarkuptrue%
   559 \isamarkuptrue%
   580 %
   560 %
   581 \isamarkupsubsection{Suppressing Output%
   561 \isamarkupsubsection{Suppressing Output \label{sec:doc-prep-suppress}%
   582 }
   562 }
   583 \isamarkuptrue%
   563 \isamarkuptrue%
   584 %
   564 %
   585 \begin{isamarkuptext}%
   565 \begin{isamarkuptext}%
   586 By default Isabelle's document system generates a {\LaTeX} source
   566 By default Isabelle's document system generates a {\LaTeX} source
   587   file for each theory that happens to get loaded during the session.
   567   file for each theory that happens to get loaded during the session.
   588   The generated \texttt{session.tex} file will include all of these in
   568   The generated \texttt{session.tex} will include all of these in
   589   order of appearance, which in turn gets included by the standard
   569   order of appearance, which in turn gets included by the standard
   590   \texttt{root.tex} file.  Certainly one may change the order of
   570   \texttt{root.tex}.  Certainly one may change the order of appearance
   591   appearance or suppress unwanted theories by ignoring
   571   or suppress unwanted theories by ignoring \texttt{session.tex} and
   592   \texttt{session.tex} and include individual files in
   572   include individual files in \texttt{root.tex} by hand.  On the other
   593   \texttt{root.tex} by hand.  On the other hand, such an arrangement
   573   hand, such an arrangement requires additional maintenance chores
   594   requires additional efforts for maintenance.
   574   whenever the collection of theories changes.
   595 
   575 
   596   Alternatively, one may tune the theory loading process in
   576   Alternatively, one may tune the theory loading process in
   597   \texttt{ROOT.ML}: traversal of the theory dependency graph may be
   577   \texttt{ROOT.ML} itself: traversal of the theory dependency graph
   598   fine-tuned by adding further \verb,use_thy, invocations, although
   578   may be fine-tuned by adding further \verb,use_thy, invocations,
   599   topological sorting needs to be preserved.  Moreover, the ML
   579   although topological sorting still has to be observed.  Moreover,
   600   operator \verb,no_document, temporarily disables document generation
   580   the ML operator \verb,no_document, temporarily disables document
   601   while executing a theory loader command; the usage is like this:
   581   generation while executing a theory loader command; its usage is
       
   582   like this:
   602 
   583 
   603 \begin{verbatim}
   584 \begin{verbatim}
   604   no_document use_thy "Aux";
   585   no_document use_thy "A";
   605 \end{verbatim}
   586 \end{verbatim}
   606 
   587 
   607   Theory output may be also suppressed \emph{partially} as well.
   588   \medskip Theory output may be also suppressed in smaller portions as
   608   Typical applications include research papers or slides based on
   589   well.  For example, research papers or slides usually do not include
   609   formal developments --- these usually do not show the full formal
   590   the formal content in full.  In order to delimit \bfindex{ignored
   610   content.  The special source comments
   591   material} special source comments
   611   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), and
   592   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), and
   612   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), are interpreted by the
   593   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), may be included in the
   613   document generator as open and close parenthesis for
   594   text.  Only the document preparation system is affected, the formal
   614   \bfindex{ignored material}.  Any text inside of (potentially nested)
   595   checking the theory is performed as before.
   615   \verb,(,\verb,*,\verb,<,\verb,*,\verb,),~\dots~\verb,(,\verb,*,\verb,>,\verb,*,\verb,),
       
   616   parentheses is just ignored from the output --- after correct formal
       
   617   checking.
       
   618 
   596 
   619   In the following example we suppress the slightly formalistic
   597   In the following example we suppress the slightly formalistic
   620   \isakeyword{theory} and \isakeyword{end} part of a theory text.
   598   \isakeyword{theory} + \isakeyword{end} surroundings a theory.
   621 
   599 
   622   \medskip
   600   \medskip
   623 
   601 
   624   \begin{tabular}{l}
   602   \begin{tabular}{l}
   625   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
   603   \verb,(,\verb,*,\verb,<,\verb,*,\verb,), \\
   631   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
   609   \verb,(,\verb,*,\verb,>,\verb,*,\verb,), \\
   632   \end{tabular}
   610   \end{tabular}
   633 
   611 
   634   \medskip
   612   \medskip
   635 
   613 
   636   Text may be suppressed at a very fine grain; thus we may even drop
   614   Text may be suppressed in a fine grained manner.  For example, we
   637   vital parts of the formal text, preventing that things have been
   615   may even drop vital parts of a formal proof, pretending that things
   638   simpler than in reality.  For example, the following ``fully
   616   have been simpler than in reality.  For example, the following
   639   automatic'' proof is actually a fake:%
   617   ``fully automatic'' proof is actually a fake:%
   640 \end{isamarkuptext}%
   618 \end{isamarkuptext}%
   641 \isamarkuptrue%
   619 \isamarkuptrue%
   642 \isacommand{lemma}\ {\isachardoublequote}x\ {\isasymnoteq}\ {\isacharparenleft}{\isadigit{0}}{\isacharcolon}{\isacharcolon}int{\isacharparenright}\ {\isasymLongrightarrow}\ {\isadigit{0}}\ {\isacharless}\ x\ {\isacharasterisk}\ x{\isachardoublequote}\isanewline
   620 \isacommand{lemma}\ {\isachardoublequote}x\ {\isasymnoteq}\ {\isacharparenleft}{\isadigit{0}}{\isacharcolon}{\isacharcolon}int{\isacharparenright}\ {\isasymLongrightarrow}\ {\isadigit{0}}\ {\isacharless}\ x\ {\isacharasterisk}\ x{\isachardoublequote}\isanewline
   643 \ \ \isamarkupfalse%
   621 \ \ \isamarkupfalse%
   644 \isacommand{by}\ {\isacharparenleft}auto{\isacharparenright}\isamarkupfalse%
   622 \isacommand{by}\ {\isacharparenleft}auto{\isacharparenright}\isamarkupfalse%
   648 
   626 
   649 \begin{verbatim}
   627 \begin{verbatim}
   650   by (auto(*<*)simp add: int_less_le(*>*))
   628   by (auto(*<*)simp add: int_less_le(*>*))
   651 \end{verbatim} %(*
   629 \end{verbatim} %(*
   652 
   630 
   653   \medskip Ignoring portions of printed text generally demands some
   631   \medskip Ignoring portions of printed does demand some care by the
   654   care by the user.  First of all, the writer is responsible not to
   632   user.  First of all, the writer is responsible not to obfuscate the
   655   obfuscate the underlying formal development in an unduly manner.  It
   633   underlying formal development in an unduly manner.  It is fairly
   656   is fairly easy to scramble the remaining visible text by referring
   634   easy to invalidate the remaining visible text, e.g.\ by referencing
   657   to questionable formal items (strange definitions, arbitrary axioms
   635   questionable formal items (strange definitions, arbitrary axioms
   658   etc.) that have been hidden from sight.
   636   etc.) that have been hidden from sight beforehand.
   659   
   637 
   660   Some minor technical subtleties of the
   638   Some minor technical subtleties of the
   661   \verb,(,\verb,*,\verb,<,\verb,*,\verb,),~\verb,(,\verb,*,\verb,>,\verb,*,\verb,),
   639   \verb,(,\verb,*,\verb,<,\verb,*,\verb,),-\verb,(,\verb,*,\verb,>,\verb,*,\verb,),
   662   elements need to be observed as well, as the system performs little
   640   elements need to be kept in mind as well, since the system performs
   663   sanity checks here.  Arguments of markup commands and formal
   641   little sanity checks here.  Arguments of markup commands and formal
   664   comments must not be hidden, otherwise presentation fails.  Open and
   642   comments must not be hidden, otherwise presentation fails.  Open and
   665   close parentheses need to be inserted carefully; it is fairly easy
   643   close parentheses need to be inserted carefully; it is fairly easy
   666   to hide just the wrong parts, especially after rearranging the
   644   to hide the wrong parts, especially after rearranging the sources.
   667   sources.
       
   668 
   645 
   669   \medskip Authentic reports of formal theories, say as part of a
   646   \medskip Authentic reports of formal theories, say as part of a
   670   library, should usually refrain from suppressing parts of the text
   647   library, usually should refrain from suppressing parts of the text
   671   at all.  Other users may need the full information for their own
   648   at all.  Other users may need the full information for their own
   672   derivative work.  If a particular formalization works out as too
   649   derivative work.  If a particular formalization appears inadequate
   673   ugly for general public coverage, it is often better to think of a
   650   for general public coverage, it is often more appropriate to think
   674   better way in the first place.%
   651   of a better way in the first place.%
   675 \end{isamarkuptext}%
   652 \end{isamarkuptext}%
   676 \isamarkuptrue%
   653 \isamarkuptrue%
   677 \isamarkupfalse%
   654 \isamarkupfalse%
   678 \end{isabellebody}%
   655 \end{isabellebody}%
   679 %%% Local Variables:
   656 %%% Local Variables: