src/Doc/Isar_Ref/Document_Preparation.thy
author wenzelm
Wed Mar 25 11:39:52 2015 +0100 (2015-03-25)
changeset 59809 87641097d0f3
parent 59783 00b62aa9f430
child 59917 9830c944670f
permissions -rw-r--r--
tuned signature;
wenzelm@27043
     1
theory Document_Preparation
wenzelm@42651
     2
imports Base Main
wenzelm@27043
     3
begin
wenzelm@27043
     4
wenzelm@58618
     5
chapter \<open>Document preparation \label{ch:document-prep}\<close>
wenzelm@27043
     6
wenzelm@58618
     7
text \<open>Isabelle/Isar provides a simple document preparation system
wenzelm@54346
     8
  based on {PDF-\LaTeX}, with support for hyperlinks and bookmarks
wenzelm@54346
     9
  within that format.  This allows to produce papers, books, theses
wenzelm@54346
    10
  etc.\ from Isabelle theory sources.
wenzelm@27043
    11
wenzelm@51057
    12
  {\LaTeX} output is generated while processing a \emph{session} in
wenzelm@51057
    13
  batch mode, as explained in the \emph{The Isabelle System Manual}
wenzelm@58552
    14
  @{cite "isabelle-sys"}.  The main Isabelle tools to get started with
wenzelm@54346
    15
  document preparation are @{tool_ref mkroot} and @{tool_ref build}.
wenzelm@27043
    16
wenzelm@58552
    17
  The classic Isabelle/HOL tutorial @{cite "isabelle-hol-book"} also
wenzelm@58618
    18
  explains some aspects of theory presentation.\<close>
wenzelm@27043
    19
wenzelm@27043
    20
wenzelm@58618
    21
section \<open>Markup commands \label{sec:markup}\<close>
wenzelm@27043
    22
wenzelm@58618
    23
text \<open>
wenzelm@27043
    24
  \begin{matharray}{rcl}
wenzelm@58868
    25
    @{command_def "chapter"} & : & @{text "any \<rightarrow> any"} \\
wenzelm@58868
    26
    @{command_def "section"} & : & @{text "any \<rightarrow> any"} \\
wenzelm@58868
    27
    @{command_def "subsection"} & : & @{text "any \<rightarrow> any"} \\
wenzelm@58868
    28
    @{command_def "subsubsection"} & : & @{text "any \<rightarrow> any"} \\
wenzelm@58999
    29
    @{command_def "text"} & : & @{text "any \<rightarrow> any"} \\
wenzelm@58999
    30
    @{command_def "txt"} & : & @{text "any \<rightarrow> any"} \\
wenzelm@58999
    31
    @{command_def "text_raw"} & : & @{text "any \<rightarrow> any"} \\
wenzelm@27043
    32
  \end{matharray}
wenzelm@27043
    33
wenzelm@28747
    34
  Markup commands provide a structured way to insert text into the
wenzelm@28747
    35
  document generated from a theory.  Each markup command takes a
wenzelm@28747
    36
  single @{syntax text} argument, which is passed as argument to a
wenzelm@28747
    37
  corresponding {\LaTeX} macro.  The default macros provided by
wenzelm@40800
    38
  @{file "~~/lib/texinputs/isabelle.sty"} can be redefined according
wenzelm@28747
    39
  to the needs of the underlying document and {\LaTeX} styles.
wenzelm@28747
    40
wenzelm@28747
    41
  Note that formal comments (\secref{sec:comments}) are similar to
wenzelm@28747
    42
  markup commands, but have a different status within Isabelle/Isar
wenzelm@28747
    43
  syntax.
wenzelm@27043
    44
wenzelm@55112
    45
  @{rail \<open>
wenzelm@42596
    46
    (@@{command chapter} | @@{command section} | @@{command subsection} |
wenzelm@59783
    47
      @@{command subsubsection} | @@{command text} | @@{command txt}) @{syntax text}
wenzelm@27043
    48
    ;
wenzelm@58999
    49
    @@{command text_raw} @{syntax text}
wenzelm@55112
    50
  \<close>}
wenzelm@27043
    51
wenzelm@28760
    52
  \begin{description}
wenzelm@27043
    53
wenzelm@58868
    54
  \item @{command chapter}, @{command section}, @{command subsection}, and
wenzelm@58868
    55
  @{command subsubsection} mark chapter and section headings within the
wenzelm@58868
    56
  theory source; this works in any context, even before the initial
wenzelm@58868
    57
  @{command theory} command. The corresponding {\LaTeX} macros are
wenzelm@58868
    58
  @{verbatim \<open>\isamarkupchapter\<close>}, @{verbatim \<open>\isamarkupsection\<close>},
wenzelm@58868
    59
  @{verbatim \<open>\isamarkupsubsection\<close>}, @{verbatim \<open>\isamarkupsubsubsection\<close>}.
wenzelm@27043
    60
wenzelm@58999
    61
  \item @{command text} and @{command txt} specify paragraphs of plain text.
wenzelm@58999
    62
  This corresponds to a {\LaTeX} environment @{verbatim
wenzelm@58999
    63
  \<open>\begin{isamarkuptext}\<close>} @{text "\<dots>"} @{verbatim \<open>\end{isamarkuptext}\<close>}
wenzelm@58999
    64
  etc.
wenzelm@27043
    65
wenzelm@58999
    66
  \item @{command text_raw} inserts {\LaTeX} source directly into the
wenzelm@58999
    67
  output, without additional markup. Thus the full range of document
wenzelm@58999
    68
  manipulations becomes available, at the risk of messing up document
wenzelm@58999
    69
  output.
wenzelm@27043
    70
wenzelm@28760
    71
  \end{description}
wenzelm@27043
    72
wenzelm@58999
    73
  Except for @{command "text_raw"}, the text passed to any of the above
wenzelm@58999
    74
  markup commands may refer to formal entities via \emph{document
wenzelm@58999
    75
  antiquotations}, see also \secref{sec:antiq}. These are interpreted in the
wenzelm@59783
    76
  present theory or proof context.
wenzelm@27043
    77
wenzelm@27043
    78
  \medskip The proof markup commands closely resemble those for theory
wenzelm@27043
    79
  specifications, but have a different formal status and produce
wenzelm@58868
    80
  different {\LaTeX} macros.
wenzelm@58618
    81
\<close>
wenzelm@27043
    82
wenzelm@27043
    83
wenzelm@58618
    84
section \<open>Document Antiquotations \label{sec:antiq}\<close>
wenzelm@27043
    85
wenzelm@58618
    86
text \<open>
wenzelm@27043
    87
  \begin{matharray}{rcl}
wenzelm@28761
    88
    @{antiquotation_def "theory"} & : & @{text antiquotation} \\
wenzelm@28761
    89
    @{antiquotation_def "thm"} & : & @{text antiquotation} \\
wenzelm@28761
    90
    @{antiquotation_def "lemma"} & : & @{text antiquotation} \\
wenzelm@28761
    91
    @{antiquotation_def "prop"} & : & @{text antiquotation} \\
wenzelm@28761
    92
    @{antiquotation_def "term"} & : & @{text antiquotation} \\
haftmann@32898
    93
    @{antiquotation_def term_type} & : & @{text antiquotation} \\
haftmann@32898
    94
    @{antiquotation_def typeof} & : & @{text antiquotation} \\
wenzelm@28761
    95
    @{antiquotation_def const} & : & @{text antiquotation} \\
wenzelm@28761
    96
    @{antiquotation_def abbrev} & : & @{text antiquotation} \\
wenzelm@28761
    97
    @{antiquotation_def typ} & : & @{text antiquotation} \\
haftmann@39305
    98
    @{antiquotation_def type} & : & @{text antiquotation} \\
haftmann@39305
    99
    @{antiquotation_def class} & : & @{text antiquotation} \\
wenzelm@28761
   100
    @{antiquotation_def "text"} & : & @{text antiquotation} \\
wenzelm@28761
   101
    @{antiquotation_def goals} & : & @{text antiquotation} \\
wenzelm@28761
   102
    @{antiquotation_def subgoals} & : & @{text antiquotation} \\
wenzelm@28761
   103
    @{antiquotation_def prf} & : & @{text antiquotation} \\
wenzelm@28761
   104
    @{antiquotation_def full_prf} & : & @{text antiquotation} \\
wenzelm@28761
   105
    @{antiquotation_def ML} & : & @{text antiquotation} \\
wenzelm@46261
   106
    @{antiquotation_def ML_op} & : & @{text antiquotation} \\
wenzelm@28761
   107
    @{antiquotation_def ML_type} & : & @{text antiquotation} \\
wenzelm@55837
   108
    @{antiquotation_def ML_structure} & : & @{text antiquotation} \\
wenzelm@55837
   109
    @{antiquotation_def ML_functor} & : & @{text antiquotation} \\
wenzelm@58716
   110
    @{antiquotation_def verbatim} & : & @{text antiquotation} \\
wenzelm@40801
   111
    @{antiquotation_def "file"} & : & @{text antiquotation} \\
wenzelm@54702
   112
    @{antiquotation_def "url"} & : & @{text antiquotation} \\
wenzelm@58593
   113
    @{antiquotation_def "cite"} & : & @{text antiquotation} \\
wenzelm@27043
   114
  \end{matharray}
wenzelm@27043
   115
wenzelm@28749
   116
  The overall content of an Isabelle/Isar theory may alternate between
wenzelm@28749
   117
  formal and informal text.  The main body consists of formal
wenzelm@28749
   118
  specification and proof commands, interspersed with markup commands
wenzelm@28749
   119
  (\secref{sec:markup}) or document comments (\secref{sec:comments}).
wenzelm@28749
   120
  The argument of markup commands quotes informal text to be printed
wenzelm@28749
   121
  in the resulting document, but may again refer to formal entities
wenzelm@28749
   122
  via \emph{document antiquotations}.
wenzelm@27043
   123
wenzelm@58724
   124
  For example, embedding @{verbatim \<open>@{term [show_types] "f x = a + x"}\<close>}
wenzelm@28749
   125
  within a text block makes
wenzelm@28749
   126
  \isa{{\isacharparenleft}f{\isasymColon}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isacharparenright}\ {\isacharparenleft}x{\isasymColon}{\isacharprime}a{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}a{\isasymColon}{\isacharprime}a{\isacharparenright}\ {\isacharplus}\ x} appear in the final {\LaTeX} document.
wenzelm@28749
   127
wenzelm@28749
   128
  Antiquotations usually spare the author tedious typing of logical
wenzelm@28749
   129
  entities in full detail.  Even more importantly, some degree of
wenzelm@28749
   130
  consistency-checking between the main body of formal text and its
wenzelm@28749
   131
  informal explanation is achieved, since terms and types appearing in
wenzelm@28749
   132
  antiquotations are checked within the current theory or proof
wenzelm@28749
   133
  context.
wenzelm@27043
   134
wenzelm@43618
   135
  %% FIXME less monolithic presentation, move to individual sections!?
wenzelm@55112
   136
  @{rail \<open>
wenzelm@42596
   137
    '@{' antiquotation '}'
wenzelm@27043
   138
    ;
wenzelm@42596
   139
    @{syntax_def antiquotation}:
wenzelm@42596
   140
      @@{antiquotation theory} options @{syntax name} |
wenzelm@42596
   141
      @@{antiquotation thm} options styles @{syntax thmrefs} |
wenzelm@42617
   142
      @@{antiquotation lemma} options @{syntax prop} @'by' @{syntax method} @{syntax method}? |
wenzelm@42596
   143
      @@{antiquotation prop} options styles @{syntax prop} |
wenzelm@42596
   144
      @@{antiquotation term} options styles @{syntax term} |
wenzelm@43618
   145
      @@{antiquotation (HOL) value} options styles @{syntax term} |
wenzelm@42596
   146
      @@{antiquotation term_type} options styles @{syntax term} |
wenzelm@42596
   147
      @@{antiquotation typeof} options styles @{syntax term} |
wenzelm@42596
   148
      @@{antiquotation const} options @{syntax term} |
wenzelm@42596
   149
      @@{antiquotation abbrev} options @{syntax term} |
wenzelm@42596
   150
      @@{antiquotation typ} options @{syntax type} |
wenzelm@42596
   151
      @@{antiquotation type} options @{syntax name} |
wenzelm@42596
   152
      @@{antiquotation class} options @{syntax name} |
wenzelm@58069
   153
      @@{antiquotation text} options @{syntax text}
wenzelm@46261
   154
    ;
wenzelm@46261
   155
    @{syntax antiquotation}:
wenzelm@42596
   156
      @@{antiquotation goals} options |
wenzelm@42596
   157
      @@{antiquotation subgoals} options |
wenzelm@42596
   158
      @@{antiquotation prf} options @{syntax thmrefs} |
wenzelm@42596
   159
      @@{antiquotation full_prf} options @{syntax thmrefs} |
wenzelm@58069
   160
      @@{antiquotation ML} options @{syntax text} |
wenzelm@58069
   161
      @@{antiquotation ML_op} options @{syntax text} |
wenzelm@58069
   162
      @@{antiquotation ML_type} options @{syntax text} |
wenzelm@58069
   163
      @@{antiquotation ML_structure} options @{syntax text} |
wenzelm@58069
   164
      @@{antiquotation ML_functor} options @{syntax text} |
wenzelm@58716
   165
      @@{antiquotation verbatim} options @{syntax text} |
wenzelm@55112
   166
      @@{antiquotation "file"} options @{syntax name} |
wenzelm@54705
   167
      @@{antiquotation file_unchecked} options @{syntax name} |
wenzelm@58593
   168
      @@{antiquotation url} options @{syntax name} |
wenzelm@58593
   169
      @@{antiquotation cite} options @{syntax cartouche}? (@{syntax name} + @'and')
wenzelm@27043
   170
    ;
wenzelm@27043
   171
    options: '[' (option * ',') ']'
wenzelm@27043
   172
    ;
wenzelm@42596
   173
    option: @{syntax name} | @{syntax name} '=' @{syntax name}
wenzelm@27043
   174
    ;
haftmann@32892
   175
    styles: '(' (style + ',') ')'
haftmann@32891
   176
    ;
wenzelm@42596
   177
    style: (@{syntax name} +)
wenzelm@55112
   178
  \<close>}
wenzelm@27043
   179
wenzelm@27043
   180
  Note that the syntax of antiquotations may \emph{not} include source
wenzelm@28749
   181
  comments @{verbatim "(*"}~@{text "\<dots>"}~@{verbatim "*)"} nor verbatim
wenzelm@58725
   182
  text @{verbatim "{*"}~@{text "\<dots>"}~@{verbatim "*}"}.
wenzelm@27043
   183
wenzelm@28760
   184
  \begin{description}
wenzelm@27043
   185
  
wenzelm@28760
   186
  \item @{text "@{theory A}"} prints the name @{text "A"}, which is
wenzelm@27043
   187
  guaranteed to refer to a valid ancestor theory in the current
wenzelm@27043
   188
  context.
wenzelm@27043
   189
wenzelm@28760
   190
  \item @{text "@{thm a\<^sub>1 \<dots> a\<^sub>n}"} prints theorems @{text "a\<^sub>1 \<dots> a\<^sub>n"}.
wenzelm@28749
   191
  Full fact expressions are allowed here, including attributes
wenzelm@28749
   192
  (\secref{sec:syn-att}).
wenzelm@27043
   193
wenzelm@28760
   194
  \item @{text "@{prop \<phi>}"} prints a well-typed proposition @{text
wenzelm@27043
   195
  "\<phi>"}.
wenzelm@27043
   196
wenzelm@28760
   197
  \item @{text "@{lemma \<phi> by m}"} proves a well-typed proposition
wenzelm@28749
   198
  @{text "\<phi>"} by method @{text m} and prints the original @{text "\<phi>"}.
haftmann@27453
   199
wenzelm@28760
   200
  \item @{text "@{term t}"} prints a well-typed term @{text "t"}.
bulwahn@43613
   201
  
wenzelm@43618
   202
  \item @{text "@{value t}"} evaluates a term @{text "t"} and prints
wenzelm@43618
   203
  its result, see also @{command_ref (HOL) value}.
wenzelm@27043
   204
haftmann@32898
   205
  \item @{text "@{term_type t}"} prints a well-typed term @{text "t"}
haftmann@32898
   206
  annotated with its type.
haftmann@32898
   207
haftmann@32898
   208
  \item @{text "@{typeof t}"} prints the type of a well-typed term
haftmann@32898
   209
  @{text "t"}.
haftmann@32898
   210
wenzelm@28760
   211
  \item @{text "@{const c}"} prints a logical or syntactic constant
wenzelm@27043
   212
  @{text "c"}.
wenzelm@27043
   213
  
wenzelm@28760
   214
  \item @{text "@{abbrev c x\<^sub>1 \<dots> x\<^sub>n}"} prints a constant abbreviation
wenzelm@28760
   215
  @{text "c x\<^sub>1 \<dots> x\<^sub>n \<equiv> rhs"} as defined in the current context.
haftmann@39305
   216
wenzelm@28760
   217
  \item @{text "@{typ \<tau>}"} prints a well-formed type @{text "\<tau>"}.
haftmann@39305
   218
wenzelm@39689
   219
  \item @{text "@{type \<kappa>}"} prints a (logical or syntactic) type
wenzelm@39689
   220
    constructor @{text "\<kappa>"}.
haftmann@39305
   221
haftmann@39305
   222
  \item @{text "@{class c}"} prints a class @{text c}.
haftmann@39305
   223
wenzelm@28760
   224
  \item @{text "@{text s}"} prints uninterpreted source text @{text
wenzelm@27043
   225
  s}.  This is particularly useful to print portions of text according
wenzelm@28749
   226
  to the Isabelle document style, without demanding well-formedness,
wenzelm@28749
   227
  e.g.\ small pieces of terms that should not be parsed or
wenzelm@28749
   228
  type-checked yet.
wenzelm@27043
   229
wenzelm@28760
   230
  \item @{text "@{goals}"} prints the current \emph{dynamic} goal
wenzelm@27043
   231
  state.  This is mainly for support of tactic-emulation scripts
wenzelm@28749
   232
  within Isar.  Presentation of goal states does not conform to the
wenzelm@28749
   233
  idea of human-readable proof documents!
wenzelm@27043
   234
wenzelm@28749
   235
  When explaining proofs in detail it is usually better to spell out
wenzelm@28749
   236
  the reasoning via proper Isar proof commands, instead of peeking at
wenzelm@28749
   237
  the internal machine configuration.
wenzelm@27043
   238
  
wenzelm@28760
   239
  \item @{text "@{subgoals}"} is similar to @{text "@{goals}"}, but
wenzelm@27043
   240
  does not print the main goal.
wenzelm@27043
   241
  
wenzelm@28760
   242
  \item @{text "@{prf a\<^sub>1 \<dots> a\<^sub>n}"} prints the (compact) proof terms
wenzelm@28749
   243
  corresponding to the theorems @{text "a\<^sub>1 \<dots> a\<^sub>n"}. Note that this
wenzelm@28749
   244
  requires proof terms to be switched on for the current logic
wenzelm@28749
   245
  session.
wenzelm@27043
   246
  
wenzelm@28760
   247
  \item @{text "@{full_prf a\<^sub>1 \<dots> a\<^sub>n}"} is like @{text "@{prf a\<^sub>1 \<dots>
wenzelm@28760
   248
  a\<^sub>n}"}, but prints the full proof terms, i.e.\ also displays
wenzelm@28760
   249
  information omitted in the compact proof term, which is denoted by
wenzelm@28760
   250
  ``@{text _}'' placeholders there.
wenzelm@27043
   251
  
wenzelm@46261
   252
  \item @{text "@{ML s}"}, @{text "@{ML_op s}"}, @{text "@{ML_type
wenzelm@55837
   253
  s}"}, @{text "@{ML_structure s}"}, and @{text "@{ML_functor s}"}
wenzelm@55837
   254
  check text @{text s} as ML value, infix operator, type, structure,
wenzelm@55837
   255
  and functor respectively.  The source is printed verbatim.
wenzelm@27043
   256
wenzelm@58716
   257
  \item @{text "@{verbatim s}"} prints uninterpreted source text literally
wenzelm@58716
   258
  as ASCII characters, using some type-writer font style.
wenzelm@58716
   259
wenzelm@40801
   260
  \item @{text "@{file path}"} checks that @{text "path"} refers to a
wenzelm@40801
   261
  file (or directory) and prints it verbatim.
wenzelm@40801
   262
wenzelm@54705
   263
  \item @{text "@{file_unchecked path}"} is like @{text "@{file
wenzelm@54705
   264
  path}"}, but does not check the existence of the @{text "path"}
wenzelm@54705
   265
  within the file-system.
wenzelm@54705
   266
wenzelm@54702
   267
  \item @{text "@{url name}"} produces markup for the given URL, which
wenzelm@54702
   268
  results in an active hyperlink within the text.
wenzelm@54702
   269
wenzelm@58593
   270
  \item @{text "@{cite name}"} produces a citation @{verbatim
wenzelm@58724
   271
  \<open>\cite{name}\<close>} in {\LaTeX}, where the name refers to some Bib{\TeX}
wenzelm@58593
   272
  database entry.
wenzelm@58593
   273
wenzelm@58593
   274
  The variant @{text "@{cite \<open>opt\<close> name}"} produces @{verbatim
wenzelm@58724
   275
  \<open>\cite[opt]{name}\<close>} with some free-form optional argument. Multiple names
wenzelm@58593
   276
  are output with commas, e.g. @{text "@{cite foo \<AND> bar}"} becomes
wenzelm@58724
   277
  @{verbatim \<open>\cite{foo,bar}\<close>}.
wenzelm@58593
   278
wenzelm@58593
   279
  The {\LaTeX} macro name is determined by the antiquotation option
wenzelm@58593
   280
  @{antiquotation_option_def cite_macro}, or the configuration option
wenzelm@58593
   281
  @{attribute cite_macro} in the context. For example, @{text "@{cite
wenzelm@58724
   282
  [cite_macro = nocite] foobar}"} produces @{verbatim \<open>\nocite{foobar}\<close>}.
wenzelm@58593
   283
wenzelm@28760
   284
  \end{description}
wenzelm@58618
   285
\<close>
wenzelm@27043
   286
wenzelm@28749
   287
wenzelm@58618
   288
subsection \<open>Styled antiquotations\<close>
wenzelm@28749
   289
wenzelm@58618
   290
text \<open>The antiquotations @{text thm}, @{text prop} and @{text
haftmann@32891
   291
  term} admit an extra \emph{style} specification to modify the
haftmann@32891
   292
  printed result.  A style is specified by a name with a possibly
haftmann@32891
   293
  empty number of arguments;  multiple styles can be sequenced with
haftmann@32891
   294
  commas.  The following standard styles are available:
wenzelm@27043
   295
wenzelm@28760
   296
  \begin{description}
wenzelm@27043
   297
  
wenzelm@28760
   298
  \item @{text lhs} extracts the first argument of any application
wenzelm@28749
   299
  form with at least two arguments --- typically meta-level or
wenzelm@27043
   300
  object-level equality, or any other binary relation.
wenzelm@27043
   301
  
wenzelm@28760
   302
  \item @{text rhs} is like @{text lhs}, but extracts the second
wenzelm@27043
   303
  argument.
wenzelm@27043
   304
  
wenzelm@28760
   305
  \item @{text "concl"} extracts the conclusion @{text C} from a rule
wenzelm@27043
   306
  in Horn-clause normal form @{text "A\<^sub>1 \<Longrightarrow> \<dots> A\<^sub>n \<Longrightarrow> C"}.
wenzelm@27043
   307
  
haftmann@32891
   308
  \item @{text "prem"} @{text n} extract premise number
haftmann@32891
   309
  @{text "n"} from from a rule in Horn-clause
wenzelm@28760
   310
  normal form @{text "A\<^sub>1 \<Longrightarrow> \<dots> A\<^sub>n \<Longrightarrow> C"}
wenzelm@27043
   311
wenzelm@28760
   312
  \end{description}
wenzelm@58618
   313
\<close>
wenzelm@27043
   314
wenzelm@28749
   315
wenzelm@58618
   316
subsection \<open>General options\<close>
wenzelm@28749
   317
wenzelm@58618
   318
text \<open>The following options are available to tune the printed output
wenzelm@54346
   319
  of antiquotations.  Note that many of these coincide with system and
wenzelm@54346
   320
  configuration options of the same names.
wenzelm@27043
   321
wenzelm@28760
   322
  \begin{description}
wenzelm@27043
   323
wenzelm@30397
   324
  \item @{antiquotation_option_def show_types}~@{text "= bool"} and
wenzelm@30397
   325
  @{antiquotation_option_def show_sorts}~@{text "= bool"} control
wenzelm@30397
   326
  printing of explicit type and sort constraints.
wenzelm@27043
   327
wenzelm@30397
   328
  \item @{antiquotation_option_def show_structs}~@{text "= bool"}
wenzelm@30397
   329
  controls printing of implicit structures.
wenzelm@27043
   330
wenzelm@40879
   331
  \item @{antiquotation_option_def show_abbrevs}~@{text "= bool"}
wenzelm@40879
   332
  controls folding of abbreviations.
wenzelm@40879
   333
wenzelm@42669
   334
  \item @{antiquotation_option_def names_long}~@{text "= bool"} forces
wenzelm@30397
   335
  names of types and constants etc.\ to be printed in their fully
wenzelm@30397
   336
  qualified internal form.
wenzelm@27043
   337
wenzelm@42669
   338
  \item @{antiquotation_option_def names_short}~@{text "= bool"}
wenzelm@30397
   339
  forces names of types and constants etc.\ to be printed unqualified.
wenzelm@30397
   340
  Note that internalizing the output again in the current context may
wenzelm@30397
   341
  well yield a different result.
wenzelm@27043
   342
wenzelm@42669
   343
  \item @{antiquotation_option_def names_unique}~@{text "= bool"}
wenzelm@30397
   344
  determines whether the printed version of qualified names should be
wenzelm@30397
   345
  made sufficiently long to avoid overlap with names declared further
wenzelm@30397
   346
  back.  Set to @{text false} for more concise output.
wenzelm@27043
   347
wenzelm@30397
   348
  \item @{antiquotation_option_def eta_contract}~@{text "= bool"}
wenzelm@30397
   349
  prints terms in @{text \<eta>}-contracted form.
wenzelm@27043
   350
wenzelm@30397
   351
  \item @{antiquotation_option_def display}~@{text "= bool"} indicates
wenzelm@30397
   352
  if the text is to be output as multi-line ``display material'',
wenzelm@30397
   353
  rather than a small piece of text without line breaks (which is the
wenzelm@30397
   354
  default).
wenzelm@27043
   355
wenzelm@28749
   356
  In this mode the embedded entities are printed in the same style as
wenzelm@28749
   357
  the main theory text.
wenzelm@28749
   358
wenzelm@30397
   359
  \item @{antiquotation_option_def break}~@{text "= bool"} controls
wenzelm@30397
   360
  line breaks in non-display material.
wenzelm@27043
   361
wenzelm@30397
   362
  \item @{antiquotation_option_def quotes}~@{text "= bool"} indicates
wenzelm@30397
   363
  if the output should be enclosed in double quotes.
wenzelm@27043
   364
wenzelm@30397
   365
  \item @{antiquotation_option_def mode}~@{text "= name"} adds @{text
wenzelm@30397
   366
  name} to the print mode to be used for presentation.  Note that the
wenzelm@30397
   367
  standard setup for {\LaTeX} output is already present by default,
wenzelm@30397
   368
  including the modes @{text latex} and @{text xsymbols}.
wenzelm@27043
   369
wenzelm@30397
   370
  \item @{antiquotation_option_def margin}~@{text "= nat"} and
wenzelm@30397
   371
  @{antiquotation_option_def indent}~@{text "= nat"} change the margin
wenzelm@30397
   372
  or indentation for pretty printing of display material.
wenzelm@27043
   373
wenzelm@30397
   374
  \item @{antiquotation_option_def goals_limit}~@{text "= nat"}
wenzelm@51960
   375
  determines the maximum number of subgoals to be printed (for goal-based
wenzelm@30397
   376
  antiquotation).
wenzelm@27043
   377
wenzelm@30397
   378
  \item @{antiquotation_option_def source}~@{text "= bool"} prints the
wenzelm@30397
   379
  original source text of the antiquotation arguments, rather than its
wenzelm@30397
   380
  internal representation.  Note that formal checking of
wenzelm@30397
   381
  @{antiquotation "thm"}, @{antiquotation "term"}, etc. is still
wenzelm@30397
   382
  enabled; use the @{antiquotation "text"} antiquotation for unchecked
wenzelm@30397
   383
  output.
wenzelm@28749
   384
wenzelm@28749
   385
  Regular @{text "term"} and @{text "typ"} antiquotations with @{text
wenzelm@28749
   386
  "source = false"} involve a full round-trip from the original source
wenzelm@28749
   387
  to an internalized logical entity back to a source form, according
wenzelm@28749
   388
  to the syntax of the current context.  Thus the printed output is
wenzelm@28749
   389
  not under direct control of the author, it may even fluctuate a bit
wenzelm@28749
   390
  as the underlying theory is changed later on.
wenzelm@28749
   391
wenzelm@42626
   392
  In contrast, @{antiquotation_option source}~@{text "= true"}
wenzelm@30397
   393
  admits direct printing of the given source text, with the desirable
wenzelm@30397
   394
  well-formedness check in the background, but without modification of
wenzelm@30397
   395
  the printed text.
wenzelm@28749
   396
wenzelm@28760
   397
  \end{description}
wenzelm@27043
   398
wenzelm@56594
   399
  For Boolean flags, ``@{text "name = true"}'' may be abbreviated as
wenzelm@27043
   400
  ``@{text name}''.  All of the above flags are disabled by default,
wenzelm@51057
   401
  unless changed specifically for a logic session in the corresponding
wenzelm@58618
   402
  @{verbatim "ROOT"} file.\<close>
wenzelm@27043
   403
wenzelm@27043
   404
wenzelm@58618
   405
section \<open>Markup via command tags \label{sec:tags}\<close>
wenzelm@27043
   406
wenzelm@58618
   407
text \<open>Each Isabelle/Isar command may be decorated by additional
wenzelm@28750
   408
  presentation tags, to indicate some modification in the way it is
wenzelm@28750
   409
  printed in the document.
wenzelm@27043
   410
wenzelm@55112
   411
  @{rail \<open>
wenzelm@42596
   412
    @{syntax_def tags}: ( tag * )
wenzelm@27043
   413
    ;
wenzelm@42596
   414
    tag: '%' (@{syntax ident} | @{syntax string})
wenzelm@55112
   415
  \<close>}
wenzelm@27043
   416
wenzelm@28750
   417
  Some tags are pre-declared for certain classes of commands, serving
wenzelm@28750
   418
  as default markup if no tags are given in the text:
wenzelm@27043
   419
wenzelm@28750
   420
  \medskip
wenzelm@27043
   421
  \begin{tabular}{ll}
wenzelm@27043
   422
    @{text "theory"} & theory begin/end \\
wenzelm@27043
   423
    @{text "proof"} & all proof commands \\
wenzelm@27043
   424
    @{text "ML"} & all commands involving ML code \\
wenzelm@27043
   425
  \end{tabular}
wenzelm@27043
   426
wenzelm@28750
   427
  \medskip The Isabelle document preparation system
wenzelm@58552
   428
  @{cite "isabelle-sys"} allows tagged command regions to be presented
wenzelm@27043
   429
  specifically, e.g.\ to fold proof texts, or drop parts of the text
wenzelm@27043
   430
  completely.
wenzelm@27043
   431
wenzelm@28750
   432
  For example ``@{command "by"}~@{text "%invisible auto"}'' causes
wenzelm@28750
   433
  that piece of proof to be treated as @{text invisible} instead of
wenzelm@28750
   434
  @{text "proof"} (the default), which may be shown or hidden
wenzelm@27043
   435
  depending on the document setup.  In contrast, ``@{command
wenzelm@28750
   436
  "by"}~@{text "%visible auto"}'' forces this text to be shown
wenzelm@27043
   437
  invariably.
wenzelm@27043
   438
wenzelm@27043
   439
  Explicit tag specifications within a proof apply to all subsequent
wenzelm@27043
   440
  commands of the same level of nesting.  For example, ``@{command
wenzelm@28750
   441
  "proof"}~@{text "%visible \<dots>"}~@{command "qed"}'' forces the whole
wenzelm@28750
   442
  sub-proof to be typeset as @{text visible} (unless some of its parts
wenzelm@28750
   443
  are tagged differently).
wenzelm@28750
   444
wenzelm@28750
   445
  \medskip Command tags merely produce certain markup environments for
wenzelm@28750
   446
  type-setting.  The meaning of these is determined by {\LaTeX}
wenzelm@40800
   447
  macros, as defined in @{file "~~/lib/texinputs/isabelle.sty"} or
wenzelm@28750
   448
  by the document author.  The Isabelle document preparation tools
wenzelm@28750
   449
  also provide some high-level options to specify the meaning of
wenzelm@28750
   450
  arbitrary tags to ``keep'', ``drop'', or ``fold'' the corresponding
wenzelm@28750
   451
  parts of the text.  Logic sessions may also specify ``document
wenzelm@28750
   452
  versions'', where given tags are interpreted in some particular way.
wenzelm@58552
   453
  Again see @{cite "isabelle-sys"} for further details.
wenzelm@58618
   454
\<close>
wenzelm@27043
   455
wenzelm@27043
   456
wenzelm@58618
   457
section \<open>Railroad diagrams\<close>
wenzelm@42658
   458
wenzelm@58618
   459
text \<open>
wenzelm@42658
   460
  \begin{matharray}{rcl}
wenzelm@42658
   461
    @{antiquotation_def "rail"} & : & @{text antiquotation} \\
wenzelm@42658
   462
  \end{matharray}
wenzelm@42658
   463
wenzelm@55113
   464
  @{rail \<open>
wenzelm@55113
   465
    'rail' (@{syntax string} | @{syntax cartouche})
wenzelm@55113
   466
  \<close>}
wenzelm@42658
   467
wenzelm@42658
   468
  The @{antiquotation rail} antiquotation allows to include syntax
wenzelm@42658
   469
  diagrams into Isabelle documents.  {\LaTeX} requires the style file
wenzelm@59116
   470
  @{file "~~/lib/texinputs/railsetup.sty"}, which can be used via
wenzelm@59116
   471
  @{verbatim \<open>\usepackage{railsetup}\<close>} in @{verbatim "root.tex"}, for
wenzelm@42658
   472
  example.
wenzelm@42658
   473
wenzelm@42658
   474
  The rail specification language is quoted here as Isabelle @{syntax
wenzelm@55120
   475
  string} or text @{syntax "cartouche"}; it has its own grammar given
wenzelm@55120
   476
  below.
wenzelm@42658
   477
wenzelm@55120
   478
  \begingroup
wenzelm@55120
   479
  \def\isasymnewline{\isatext{\tt\isacharbackslash<newline>}}
wenzelm@55112
   480
  @{rail \<open>
wenzelm@42658
   481
  rule? + ';'
wenzelm@42658
   482
  ;
wenzelm@42658
   483
  rule: ((identifier | @{syntax antiquotation}) ':')? body
wenzelm@42658
   484
  ;
wenzelm@42658
   485
  body: concatenation + '|'
wenzelm@42658
   486
  ;
wenzelm@42658
   487
  concatenation: ((atom '?'?) +) (('*' | '+') atom?)?
wenzelm@42658
   488
  ;
wenzelm@42658
   489
  atom: '(' body? ')' | identifier |
wenzelm@42658
   490
    '@'? (string | @{syntax antiquotation}) |
wenzelm@55112
   491
    '\<newline>'
wenzelm@55112
   492
  \<close>}
wenzelm@55120
   493
  \endgroup
wenzelm@42658
   494
wenzelm@42658
   495
  The lexical syntax of @{text "identifier"} coincides with that of
wenzelm@42658
   496
  @{syntax ident} in regular Isabelle syntax, but @{text string} uses
wenzelm@42658
   497
  single quotes instead of double quotes of the standard @{syntax
wenzelm@55113
   498
  string} category.
wenzelm@42658
   499
wenzelm@42658
   500
  Each @{text rule} defines a formal language (with optional name),
wenzelm@42658
   501
  using a notation that is similar to EBNF or regular expressions with
wenzelm@42658
   502
  recursion.  The meaning and visual appearance of these rail language
wenzelm@42658
   503
  elements is illustrated by the following representative examples.
wenzelm@42658
   504
wenzelm@42658
   505
  \begin{itemize}
wenzelm@42658
   506
wenzelm@42658
   507
  \item Empty @{verbatim "()"}
wenzelm@42658
   508
wenzelm@55112
   509
  @{rail \<open>()\<close>}
wenzelm@42658
   510
wenzelm@42658
   511
  \item Nonterminal @{verbatim "A"}
wenzelm@42658
   512
wenzelm@55112
   513
  @{rail \<open>A\<close>}
wenzelm@42658
   514
wenzelm@42658
   515
  \item Nonterminal via Isabelle antiquotation
wenzelm@42658
   516
  @{verbatim "@{syntax method}"}
wenzelm@42658
   517
wenzelm@55112
   518
  @{rail \<open>@{syntax method}\<close>}
wenzelm@42658
   519
wenzelm@42658
   520
  \item Terminal @{verbatim "'xyz'"}
wenzelm@42658
   521
wenzelm@55112
   522
  @{rail \<open>'xyz'\<close>}
wenzelm@42658
   523
wenzelm@42658
   524
  \item Terminal in keyword style @{verbatim "@'xyz'"}
wenzelm@42658
   525
wenzelm@55112
   526
  @{rail \<open>@'xyz'\<close>}
wenzelm@42658
   527
wenzelm@42658
   528
  \item Terminal via Isabelle antiquotation
wenzelm@42658
   529
  @{verbatim "@@{method rule}"}
wenzelm@42658
   530
wenzelm@55112
   531
  @{rail \<open>@@{method rule}\<close>}
wenzelm@42658
   532
wenzelm@42658
   533
  \item Concatenation @{verbatim "A B C"}
wenzelm@42658
   534
wenzelm@55112
   535
  @{rail \<open>A B C\<close>}
wenzelm@42658
   536
wenzelm@55029
   537
  \item Newline inside concatenation
wenzelm@55029
   538
  @{verbatim "A B C \<newline> D E F"}
wenzelm@42658
   539
wenzelm@55112
   540
  @{rail \<open>A B C \<newline> D E F\<close>}
wenzelm@42658
   541
wenzelm@42658
   542
  \item Variants @{verbatim "A | B | C"}
wenzelm@42658
   543
wenzelm@55112
   544
  @{rail \<open>A | B | C\<close>}
wenzelm@42658
   545
wenzelm@42658
   546
  \item Option @{verbatim "A ?"}
wenzelm@42658
   547
wenzelm@55112
   548
  @{rail \<open>A ?\<close>}
wenzelm@42658
   549
wenzelm@42658
   550
  \item Repetition @{verbatim "A *"}
wenzelm@42658
   551
wenzelm@55112
   552
  @{rail \<open>A *\<close>}
wenzelm@42658
   553
wenzelm@42658
   554
  \item Repetition with separator @{verbatim "A * sep"}
wenzelm@42658
   555
wenzelm@55112
   556
  @{rail \<open>A * sep\<close>}
wenzelm@42658
   557
wenzelm@42658
   558
  \item Strict repetition @{verbatim "A +"}
wenzelm@42658
   559
wenzelm@55112
   560
  @{rail \<open>A +\<close>}
wenzelm@42658
   561
wenzelm@42658
   562
  \item Strict repetition with separator @{verbatim "A + sep"}
wenzelm@42658
   563
wenzelm@55112
   564
  @{rail \<open>A + sep\<close>}
wenzelm@42658
   565
wenzelm@42658
   566
  \end{itemize}
wenzelm@58618
   567
\<close>
wenzelm@42658
   568
wenzelm@42658
   569
wenzelm@58618
   570
section \<open>Draft presentation\<close>
wenzelm@27043
   571
wenzelm@58618
   572
text \<open>
wenzelm@27043
   573
  \begin{matharray}{rcl}
wenzelm@28761
   574
    @{command_def "display_drafts"}@{text "\<^sup>*"} & : & @{text "any \<rightarrow>"} \\
wenzelm@27043
   575
  \end{matharray}
wenzelm@27043
   576
wenzelm@55112
   577
  @{rail \<open>
wenzelm@52549
   578
    @@{command display_drafts} (@{syntax name} +)
wenzelm@55112
   579
  \<close>}
wenzelm@27043
   580
wenzelm@28760
   581
  \begin{description}
wenzelm@27043
   582
wenzelm@52549
   583
  \item @{command "display_drafts"}~@{text paths} performs simple output of a
wenzelm@52549
   584
  given list of raw source files. Only those symbols that do not require
wenzelm@52549
   585
  additional {\LaTeX} packages are displayed properly, everything else is left
wenzelm@52549
   586
  verbatim.
wenzelm@27043
   587
wenzelm@28760
   588
  \end{description}
wenzelm@58618
   589
\<close>
wenzelm@27043
   590
wenzelm@27043
   591
end