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