doc-src/LaTeXsugar/Sugar/Sugar.thy
author nipkow
Fri Aug 31 15:56:19 2007 +0200 (2007-08-31)
changeset 24497 7840f760a744
parent 24496 65f3b37f80b7
child 27093 66d6da816be7
permissions -rw-r--r--
explained \isatstyle(minor)
nipkow@15337
     1
(*<*)
nipkow@15337
     2
theory Sugar
kleing@15366
     3
imports LaTeXsugar OptionalSugar
nipkow@15337
     4
begin
nipkow@15337
     5
(*>*)
nipkow@15337
     6
nipkow@15337
     7
section "Introduction"
nipkow@15337
     8
kleing@15385
     9
text{* This document is for those Isabelle users who have mastered
nipkow@15337
    10
the art of mixing \LaTeX\ text and Isabelle theories and never want to
nipkow@15337
    11
typeset a theorem by hand anymore because they have experienced the
nipkow@15337
    12
bliss of writing \verb!@!\verb!{thm[display]setsum_cartesian_product[no_vars]}!
nipkow@15337
    13
and seeing Isabelle typeset it for them:
nipkow@15337
    14
@{thm[display,eta_contract=false] setsum_cartesian_product[no_vars]}
nipkow@15342
    15
No typos, no omissions, no sweat.
nipkow@15342
    16
If you have not experienced that joy, read Chapter 4, \emph{Presenting
nipkow@15342
    17
Theories}, \cite{LNCS2283} first.
nipkow@15337
    18
nipkow@15337
    19
If you have mastered the art of Isabelle's \emph{antiquotations},
nipkow@15337
    20
i.e.\ things like the above \verb!@!\verb!{thm...}!, beware: in your vanity
nipkow@15337
    21
you may be tempted to think that all readers of the stunning ps or pdf
nipkow@15337
    22
documents you can now produce at the drop of a hat will be struck with
nipkow@15337
    23
awe at the beauty unfolding in front of their eyes. Until one day you
nipkow@15337
    24
come across that very critical of readers known as the ``common referee''.
nipkow@15337
    25
He has the nasty habit of refusing to understand unfamiliar notation
nipkow@15337
    26
like Isabelle's infamous @{text"\<lbrakk> \<rbrakk> \<Longrightarrow>"} no matter how many times you
nipkow@15337
    27
explain it in your paper. Even worse, he thinks that using @{text"\<lbrakk>
nipkow@15337
    28
\<rbrakk>"} for anything other than denotational semantics is a cardinal sin
nipkow@15342
    29
that must be punished by instant rejection.
nipkow@15337
    30
nipkow@15337
    31
nipkow@15337
    32
This document shows you how to make Isabelle and \LaTeX\ cooperate to
nipkow@15337
    33
produce ordinary looking mathematics that hides the fact that it was
nipkow@15471
    34
typeset by a machine. You merely need to load the right files:
nipkow@15471
    35
\begin{itemize}
nipkow@15471
    36
\item Import theory \texttt{LaTeXsugar} in the header of your own
nipkow@15471
    37
theory.  You may also want bits of \texttt{OptionalSugar}, which you can
nipkow@15471
    38
copy selectively into your own theory or import as a whole.  Both
nipkow@15471
    39
theories live in \texttt{HOL/Library} and are found automatically.
kleing@15378
    40
nipkow@15471
    41
\item Should you need additional \LaTeX\ packages (the text will tell
nipkow@15471
    42
you so), you include them at the beginning of your \LaTeX\ document,
nipkow@16153
    43
typically in \texttt{root.tex}. For a start, you should
nipkow@16153
    44
\verb!\usepackage{amssymb}! --- otherwise typesetting
nipkow@16153
    45
@{prop[source]"\<not>(\<exists>x. P x)"} will fail because the AMS symbol
nipkow@16153
    46
@{text"\<nexists>"} is missing.
nipkow@15471
    47
\end{itemize}
nipkow@15342
    48
*}
nipkow@15342
    49
nipkow@15342
    50
section{* HOL syntax*}
nipkow@15342
    51
nipkow@15342
    52
subsection{* Logic *}
nipkow@15342
    53
nipkow@16153
    54
text{* 
nipkow@16153
    55
  The formula @{prop[source]"\<not>(\<exists>x. P x)"} is typeset as @{prop"~(EX x. P x)"}.
nipkow@16153
    56
nipkow@16153
    57
The predefined constructs @{text"if"}, @{text"let"} and
nipkow@15342
    58
@{text"case"} are set in sans serif font to distinguish them from
nipkow@15342
    59
other functions. This improves readability:
nipkow@15342
    60
\begin{itemize}
nipkow@15342
    61
\item @{term"if b then e\<^isub>1 else e\<^isub>2"} instead of @{text"if b then e\<^isub>1 else e\<^isub>2"}.
nipkow@15342
    62
\item @{term"let x = e\<^isub>1 in e\<^isub>2"} instead of @{text"let x = e\<^isub>1 in e\<^isub>2"}.
nipkow@15342
    63
\item @{term"case x of True \<Rightarrow> e\<^isub>1 | False \<Rightarrow> e\<^isub>2"} instead of\\
nipkow@15342
    64
      @{text"case x of True \<Rightarrow> e\<^isub>1 | False \<Rightarrow> e\<^isub>2"}.
nipkow@15342
    65
\end{itemize}
nipkow@15342
    66
*}
nipkow@15342
    67
nipkow@15342
    68
subsection{* Sets *}
nipkow@15337
    69
nipkow@15342
    70
text{* Although set syntax in HOL is already close to
nipkow@15342
    71
standard, we provide a few further improvements:
nipkow@15342
    72
\begin{itemize}
nipkow@15342
    73
\item @{term"{x. P}"} instead of @{text"{x. P}"}.
nipkow@15342
    74
\item @{term"{}"} instead of @{text"{}"}.
nipkow@15342
    75
\item @{term"insert a (insert b (insert c M))"} instead of @{text"insert a (insert b (insert c M))"}.
nipkow@15342
    76
\end{itemize}
nipkow@15342
    77
*}
nipkow@15342
    78
nipkow@15342
    79
subsection{* Lists *}
nipkow@15342
    80
nipkow@15342
    81
text{* If lists are used heavily, the following notations increase readability:
nipkow@15342
    82
\begin{itemize}
nipkow@15342
    83
\item @{term"x # xs"} instead of @{text"x # xs"}.
nipkow@15342
    84
      Exceptionally, @{term"x # xs"} is also input syntax.
nipkow@15342
    85
If you prefer more space around the $\cdot$ you have to redefine
nipkow@15342
    86
\verb!\isasymcdot! in \LaTeX:
nipkow@15342
    87
\verb!\renewcommand{\isasymcdot}{\isamath{\,\cdot\,}}!
nipkow@15342
    88
nipkow@15342
    89
\item @{term"length xs"} instead of @{text"length xs"}.
kleing@15385
    90
\item @{term"nth xs n"} instead of @{text"nth xs n"},
nipkow@15342
    91
      the $n$th element of @{text xs}.
nipkow@15342
    92
nipkow@22834
    93
\item Human readers are good at converting automatically from lists to
nipkow@22834
    94
sets. Hence \texttt{OptionalSugar} contains syntax for supressing the
nipkow@22834
    95
conversion function @{const set}: for example, @{prop[source]"x \<in> set xs"}
nipkow@22834
    96
becomes @{prop"x \<in> set xs"}.
nipkow@22834
    97
kleing@15366
    98
\item The @{text"@"} operation associates implicitly to the right,
kleing@15366
    99
which leads to unpleasant line breaks if the term is too long for one
kleing@15366
   100
line. To avoid this, \texttt{OptionalSugar} contains syntax to group
kleing@15366
   101
@{text"@"}-terms to the left before printing, which leads to better
kleing@15366
   102
line breaking behaviour:
wenzelm@15673
   103
@{term[display]"term\<^isub>0 @ term\<^isub>1 @ term\<^isub>2 @ term\<^isub>3 @ term\<^isub>4 @ term\<^isub>5 @ term\<^isub>6 @ term\<^isub>7 @ term\<^isub>8 @ term\<^isub>9 @ term\<^isub>1\<^isub>0"}
kleing@15366
   104
nipkow@15342
   105
\end{itemize}
nipkow@15337
   106
*}
nipkow@15337
   107
nipkow@15337
   108
section "Printing theorems"
nipkow@15337
   109
nipkow@15689
   110
subsection "Question marks"
nipkow@15689
   111
nipkow@15689
   112
text{* If you print anything, especially theorems, containing
nipkow@15689
   113
schematic variables they are prefixed with a question mark:
nipkow@15689
   114
\verb!@!\verb!{thm conjI}! results in @{thm conjI}. Most of the time
nipkow@15689
   115
you would rather not see the question marks. There is an attribute
nipkow@15689
   116
\verb!no_vars! that you can attach to the theorem that turns its
nipkow@15689
   117
schematic into ordinary free variables: \verb!@!\verb!{thm conjI[no_vars]}!
nipkow@15689
   118
results in @{thm conjI[no_vars]}.
nipkow@15689
   119
nipkow@15689
   120
This \verb!no_vars! business can become a bit tedious.
nipkow@15689
   121
If you would rather never see question marks, simply put
nipkow@15689
   122
\begin{verbatim}
wenzelm@15983
   123
reset show_question_marks;
nipkow@15689
   124
\end{verbatim}
nipkow@15689
   125
at the beginning of your file \texttt{ROOT.ML}.
nipkow@15689
   126
The rest of this document is produced with this flag reset.
nipkow@16075
   127
nipkow@16075
   128
Hint: Resetting \verb!show_question_marks! only supresses question
nipkow@16075
   129
marks; variables that end in digits, e.g. @{text"x1"}, are still
nipkow@16075
   130
printed with a trailing @{text".0"}, e.g. @{text"x1.0"}, their
nipkow@16075
   131
internal index. This can be avoided by turning the last digit into a
nipkow@16075
   132
subscript: write \verb!x\<^isub>1! and obtain the much nicer @{text"x\<^isub>1"}. *}
nipkow@15689
   133
wenzelm@15983
   134
(*<*)ML"reset show_question_marks"(*>*)
nipkow@15689
   135
nipkow@24496
   136
subsection {*Qualified names*}
nipkow@24496
   137
nipkow@24496
   138
text{* If there are multiple declarations of the same name, Isabelle prints
nipkow@24496
   139
the qualified name, for example @{text "T.length"}, where @{text T} is the
nipkow@24496
   140
theory it is defined in, to distinguish it from the predefined @{const[source]
nipkow@24496
   141
"List.length"}. In case there is no danger of confusion, you can insist on
nipkow@24496
   142
short names (no qualifiers) by setting \verb!short_names!, typically
nipkow@24496
   143
in \texttt{ROOT.ML}:
nipkow@24496
   144
\begin{verbatim}
nipkow@24496
   145
set short_names;
nipkow@24496
   146
\end{verbatim}
nipkow@24496
   147
*}
nipkow@24496
   148
nipkow@17127
   149
subsection {*Variable names\label{sec:varnames}*}
nipkow@16395
   150
nipkow@16395
   151
text{* It sometimes happens that you want to change the name of a
nipkow@16395
   152
variable in a theorem before printing it. This can easily be achieved
nipkow@16395
   153
with the help of Isabelle's instantiation attribute \texttt{where}:
nipkow@16395
   154
@{thm conjI[where P = \<phi> and Q = \<psi>]} is the result of
nipkow@16395
   155
\begin{quote}
nipkow@16395
   156
\verb!@!\verb!{thm conjI[where P = \<phi> and Q = \<psi>]}!
nipkow@16395
   157
\end{quote}
nipkow@16395
   158
To support the ``\_''-notation for irrelevant variables
nipkow@16395
   159
the constant \texttt{DUMMY} has been introduced:
nipkow@16395
   160
@{thm fst_conv[where b = DUMMY]} is produced by
nipkow@16395
   161
\begin{quote}
nipkow@16395
   162
\verb!@!\verb!{thm fst_conv[where b = DUMMY]}!
nipkow@16395
   163
\end{quote}
nipkow@16395
   164
*}
nipkow@16395
   165
nipkow@15337
   166
subsection "Inference rules"
nipkow@15337
   167
nipkow@15342
   168
text{* To print theorems as inference rules you need to include Didier
nipkow@15342
   169
R\'emy's \texttt{mathpartir} package~\cite{mathpartir}
nipkow@15342
   170
for typesetting inference rules in your \LaTeX\ file.
nipkow@15337
   171
nipkow@15689
   172
Writing \verb!@!\verb!{thm[mode=Rule] conjI}! produces
nipkow@15689
   173
@{thm[mode=Rule] conjI}, even in the middle of a sentence.
nipkow@15342
   174
If you prefer your inference rule on a separate line, maybe with a name,
nipkow@15342
   175
\begin{center}
nipkow@15689
   176
@{thm[mode=Rule] conjI} {\sc conjI}
nipkow@15342
   177
\end{center}
nipkow@15342
   178
is produced by
nipkow@15337
   179
\begin{quote}
nipkow@15337
   180
\verb!\begin{center}!\\
nipkow@15689
   181
\verb!@!\verb!{thm[mode=Rule] conjI} {\sc conjI}!\\
nipkow@15337
   182
\verb!\end{center}!
nipkow@15337
   183
\end{quote}
nipkow@24497
   184
It is not recommended to use the standard \texttt{display} option
nipkow@15342
   185
together with \texttt{Rule} because centering does not work and because
nipkow@15342
   186
the line breaking mechanisms of \texttt{display} and \texttt{mathpartir} can
nipkow@15342
   187
clash.
nipkow@15342
   188
nipkow@15337
   189
Of course you can display multiple rules in this fashion:
nipkow@15337
   190
\begin{quote}
nipkow@24497
   191
\verb!\begin{center}!\\
nipkow@15689
   192
\verb!@!\verb!{thm[mode=Rule] conjI} {\sc conjI} \\[1ex]!\\
nipkow@15689
   193
\verb!@!\verb!{thm[mode=Rule] conjE} {\sc disjI$_1$} \qquad!\\
nipkow@15689
   194
\verb!@!\verb!{thm[mode=Rule] disjE} {\sc disjI$_2$}!\\
nipkow@15337
   195
\verb!\end{center}!
nipkow@15337
   196
\end{quote}
nipkow@15337
   197
yields
nipkow@24497
   198
\begin{center}\small
nipkow@15689
   199
@{thm[mode=Rule] conjI} {\sc conjI} \\[1ex]
nipkow@15689
   200
@{thm[mode=Rule] disjI1} {\sc disjI$_1$} \qquad
nipkow@15689
   201
@{thm[mode=Rule] disjI2} {\sc disjI$_2$}
nipkow@15337
   202
\end{center}
nipkow@15337
   203
nipkow@15342
   204
The \texttt{mathpartir} package copes well if there are too many
nipkow@15342
   205
premises for one line:
nipkow@15342
   206
\begin{center}
nipkow@15342
   207
@{prop[mode=Rule] "\<lbrakk> A \<longrightarrow> B; B \<longrightarrow> C; C \<longrightarrow> D; D \<longrightarrow> E; E \<longrightarrow> F; F \<longrightarrow> G;
nipkow@15342
   208
 G \<longrightarrow> H; H \<longrightarrow> I; I \<longrightarrow> J; J \<longrightarrow> K \<rbrakk> \<Longrightarrow> A \<longrightarrow> K"}
nipkow@15342
   209
\end{center}
nipkow@15342
   210
nipkow@15471
   211
Limitations: 1. Premises and conclusion must each not be longer than
nipkow@15471
   212
the line.  2. Premises that are @{text"\<Longrightarrow>"}-implications are again
nipkow@15471
   213
displayed with a horizontal line, which looks at least unusual.
nipkow@15471
   214
schirmer@22329
   215
schirmer@22329
   216
In case you print theorems without premises no rule will be printed by the
schirmer@22329
   217
\texttt{Rule} print mode. However, you can use \texttt{Axiom} instead:
schirmer@22329
   218
\begin{quote}
nipkow@24497
   219
\verb!\begin{center}!\\
schirmer@22329
   220
\verb!@!\verb!{thm[mode=Axiom] refl} {\sc refl}! \\
schirmer@22329
   221
\verb!\end{center}!
schirmer@22329
   222
\end{quote}
schirmer@22329
   223
yields
nipkow@24497
   224
\begin{center}
schirmer@22329
   225
@{thm[mode=Axiom] refl} {\sc refl} 
schirmer@22329
   226
\end{center}
nipkow@15337
   227
*}
nipkow@15342
   228
nipkow@24497
   229
subsection "Displays and font sizes"
nipkow@24497
   230
nipkow@24497
   231
text{* When displaying theorems with the \texttt{display} option, e.g.
nipkow@24497
   232
\verb!@!\verb!{thm[display] refl}! @{thm[display] refl} the theorem is
nipkow@24497
   233
set in small font. It uses the \LaTeX-macro \verb!\isastyle!,
nipkow@24497
   234
which is also the style that regular theory text is set in, e.g. *}
nipkow@24497
   235
nipkow@24497
   236
lemma "t = t"
nipkow@24497
   237
(*<*)oops(*>*)
nipkow@24497
   238
nipkow@24497
   239
text{* \noindent Otherwise \verb!\isastyleminor! is used,
nipkow@24497
   240
which does not modify the font size (assuming you stick to the default
nipkow@24497
   241
\verb!\isabellestyle{it}! in \texttt{root.tex}). If you prefer
nipkow@24497
   242
normal font size throughout your text, include
nipkow@24497
   243
\begin{quote}
nipkow@24497
   244
\verb!\renewcommand{\isastyle}{\isastyleminor}!
nipkow@24497
   245
\end{quote}
nipkow@24497
   246
in \texttt{root.tex}. On the other hand, if you like the small font,
nipkow@24497
   247
just put \verb!\isastyle! in front of the text in question,
nipkow@24497
   248
e.g.\ at the start of one of the center-environments above.
nipkow@24497
   249
nipkow@24497
   250
The advantage of the display option is that you can display a whole
nipkow@24497
   251
list of theorems in one go. For example,
nipkow@24497
   252
\verb!@!\verb!{thm[display] foldl.simps}!
nipkow@24497
   253
generates @{thm[display] foldl.simps}
nipkow@24497
   254
*}
nipkow@24497
   255
nipkow@24497
   256
subsection "If-then"
nipkow@15342
   257
nipkow@15342
   258
text{* If you prefer a fake ``natural language'' style you can produce
nipkow@15342
   259
the body of
nipkow@15342
   260
\newtheorem{theorem}{Theorem}
nipkow@15342
   261
\begin{theorem}
nipkow@15689
   262
@{thm[mode=IfThen] le_trans}
nipkow@15342
   263
\end{theorem}
nipkow@15342
   264
by typing
nipkow@15342
   265
\begin{quote}
nipkow@15689
   266
\verb!@!\verb!{thm[mode=IfThen] le_trans}!
nipkow@15342
   267
\end{quote}
nipkow@15342
   268
nipkow@15342
   269
In order to prevent odd line breaks, the premises are put into boxes.
nipkow@15342
   270
At times this is too drastic:
nipkow@15342
   271
\begin{theorem}
nipkow@15342
   272
@{prop[mode=IfThen] "longpremise \<Longrightarrow> longerpremise \<Longrightarrow> P(f(f(f(f(f(f(f(f(f(x)))))))))) \<Longrightarrow> longestpremise \<Longrightarrow> conclusion"}
nipkow@15342
   273
\end{theorem}
nipkow@16153
   274
In which case you should use \texttt{IfThenNoBox} instead of
nipkow@16153
   275
\texttt{IfThen}:
nipkow@15342
   276
\begin{theorem}
nipkow@15342
   277
@{prop[mode=IfThenNoBox] "longpremise \<Longrightarrow> longerpremise \<Longrightarrow> P(f(f(f(f(f(f(f(f(f(x)))))))))) \<Longrightarrow> longestpremise \<Longrightarrow> conclusion"}
nipkow@15342
   278
\end{theorem}
kleing@15366
   279
*}
nipkow@15342
   280
haftmann@16166
   281
subsection{* Doing it yourself\label{sec:yourself}*}
nipkow@16153
   282
nipkow@16153
   283
text{* If for some reason you want or need to present theorems your
nipkow@16153
   284
own way, you can extract the premises and the conclusion explicitly
nipkow@16153
   285
and combine them as you like:
nipkow@16153
   286
\begin{itemize}
haftmann@16167
   287
\item \verb!@!\verb!{thm_style prem1! $thm$\verb!}!
haftmann@16167
   288
prints premise 1 of $thm$ (and similarly up to \texttt{prem9}).
haftmann@16165
   289
\item \verb!@!\verb!{thm_style concl! $thm$\verb!}!
nipkow@16153
   290
prints the conclusion of $thm$.
nipkow@16153
   291
\end{itemize}
haftmann@16167
   292
For example, ``from @{thm_style prem2 conjI} and
haftmann@16167
   293
@{thm_style prem1 conjI} we conclude @{thm_style concl conjI}''
nipkow@16153
   294
is produced by
nipkow@16153
   295
\begin{quote}
nipkow@16175
   296
\verb!from !\verb!@!\verb!{thm_style prem2 conjI}! \verb!and !\verb!@!\verb!{thm_style prem1 conjI}!\\
haftmann@16165
   297
\verb!we conclude !\verb!@!\verb!{thm_style concl conjI}!
nipkow@16153
   298
\end{quote}
nipkow@16153
   299
Thus you can rearrange or hide premises and typeset the theorem as you like.
nipkow@16153
   300
The \verb!thm_style! antiquotation is a general mechanism explained
nipkow@16153
   301
in \S\ref{sec:styles}.
nipkow@16153
   302
*}
nipkow@16153
   303
kleing@15366
   304
subsection "Patterns"
kleing@15366
   305
kleing@15366
   306
text {*
kleing@15366
   307
nipkow@17127
   308
  In \S\ref{sec:varnames} we shows how to create patterns containing
nipkow@17127
   309
  ``@{term DUMMY}''.
kleing@15366
   310
  You can drive this game even further and extend the syntax of let
kleing@15366
   311
  bindings such that certain functions like @{term fst}, @{term hd}, 
kleing@15368
   312
  etc.\ are printed as patterns. \texttt{OptionalSugar} provides the
kleing@15368
   313
  following:
kleing@15366
   314
  
kleing@15366
   315
  \begin{center}
kleing@15366
   316
  \begin{tabular}{l@ {~~produced by~~}l}
kleing@15366
   317
  @{term "let x = fst p in t"} & \verb!@!\verb!{term "let x = fst p in t"}!\\
kleing@15366
   318
  @{term "let x = snd p in t"} & \verb!@!\verb!{term "let x = snd p in t"}!\\
kleing@15366
   319
  @{term "let x = hd xs in t"} & \verb!@!\verb!{term "let x = hd xs in t"}!\\
kleing@15366
   320
  @{term "let x = tl xs in t"} & \verb!@!\verb!{term "let x = tl xs in t"}!\\
kleing@15366
   321
  @{term "let x = the y in t"} & \verb!@!\verb!{term "let x = the y in t"}!\\
kleing@15366
   322
  \end{tabular}
kleing@15366
   323
  \end{center}
kleing@15366
   324
*}
kleing@15366
   325
nipkow@16155
   326
section "Proofs"
kleing@15366
   327
nipkow@24497
   328
text {* Full proofs, even if written in beautiful Isar style, are
nipkow@24497
   329
likely to be too long and detailed to be included in conference
nipkow@24497
   330
papers, but some key lemmas might be of interest.
nipkow@24497
   331
It is usually easiest to put them in figures like the one in Fig.\
nipkow@24497
   332
\ref{fig:proof}. This was achieved with the \isakeyword{text\_raw} command:
kleing@15366
   333
*}
kleing@15366
   334
text_raw {*
kleing@15366
   335
  \begin{figure}
kleing@15366
   336
  \begin{center}\begin{minipage}{0.6\textwidth}  
nipkow@24497
   337
  \isastyleminor\isamarkuptrue
kleing@15366
   338
*}
kleing@15366
   339
lemma True
kleing@15366
   340
proof -
kleing@15366
   341
  -- "pretty trivial"
kleing@15366
   342
  show True by force
kleing@15366
   343
qed
kleing@15428
   344
text_raw {*    
kleing@15366
   345
  \end{minipage}\end{center}
kleing@15366
   346
  \caption{Example proof in a figure.}\label{fig:proof}
kleing@15366
   347
  \end{figure}
kleing@15366
   348
*}
kleing@15366
   349
text {*
kleing@15366
   350
kleing@15366
   351
\begin{quote}
kleing@15366
   352
\small
kleing@15366
   353
\verb!text_raw {!\verb!*!\\
kleing@15366
   354
\verb!  \begin{figure}!\\
kleing@15366
   355
\verb!  \begin{center}\begin{minipage}{0.6\textwidth}!\\
nipkow@24497
   356
\verb!  \isastyleminor\isamarkuptrue!\\
kleing@15366
   357
\verb!*!\verb!}!\\
kleing@15366
   358
\verb!lemma True!\\
kleing@15366
   359
\verb!proof -!\\
kleing@15366
   360
\verb!  -- "pretty trivial"!\\
kleing@15366
   361
\verb!  show True by force!\\
kleing@15366
   362
\verb!qed!\\
kleing@15366
   363
\verb!text_raw {!\verb!*!\\
kleing@15366
   364
\verb!  \end{minipage}\end{center}!\\
kleing@15366
   365
\verb!  \caption{Example proof in a figure.}\label{fig:proof}!\\
kleing@15366
   366
\verb!  \end{figure}!\\
kleing@15366
   367
\verb!*!\verb!}!
kleing@15366
   368
\end{quote}
nipkow@24497
   369
nipkow@24497
   370
Other theory text, e.g.\ definitions, can be put in figures, too.
nipkow@15342
   371
*}
nipkow@15342
   372
nipkow@16155
   373
section {*Styles\label{sec:styles}*}
haftmann@15917
   374
haftmann@15917
   375
text {*
nipkow@15953
   376
  The \verb!thm! antiquotation works nicely for single theorems, but
haftmann@15917
   377
  sets of equations as used in definitions are more difficult to
haftmann@16040
   378
  typeset nicely: people tend to prefer aligned @{text "="} signs.
haftmann@15917
   379
haftmann@15917
   380
  To deal with such cases where it is desirable to dive into the structure
haftmann@16040
   381
  of terms and theorems, Isabelle offers antiquotations featuring
haftmann@15917
   382
  ``styles'':
haftmann@15917
   383
haftmann@15917
   384
    \begin{quote}
haftmann@15917
   385
    \verb!@!\verb!{thm_style stylename thm}!\\
haftmann@15917
   386
    \verb!@!\verb!{term_style stylename term}!
haftmann@15917
   387
    \end{quote}
haftmann@15917
   388
haftmann@16040
   389
  A ``style'' is a transformation of propositions. There are predefined
webertj@21558
   390
  styles, namely \verb!lhs! and \verb!rhs!, \verb!prem1! up to \verb!prem9!, and \verb!concl!.
haftmann@16166
   391
  For example, 
kleing@16076
   392
  the output
haftmann@15917
   393
  \begin{center}
haftmann@15917
   394
  \begin{tabular}{l@ {~~@{text "="}~~}l}
haftmann@15917
   395
  @{thm_style lhs foldl_Nil} & @{thm_style rhs foldl_Nil}\\
haftmann@15917
   396
  @{thm_style lhs foldl_Cons} & @{thm_style rhs foldl_Cons}
haftmann@15917
   397
  \end{tabular}
haftmann@15917
   398
  \end{center}
haftmann@15917
   399
  is produced by the following code:
haftmann@15917
   400
  \begin{quote}
haftmann@15917
   401
    \verb!\begin{center}!\\
haftmann@15917
   402
    \verb!\begin{tabular}{l@ {~~!\verb!@!\verb!{text "="}~~}l}!\\
haftmann@15917
   403
    \verb!@!\verb!{thm_style lhs foldl_Nil} & @!\verb!{thm_style rhs foldl_Nil}!\\
haftmann@15917
   404
    \verb!@!\verb!{thm_style lhs foldl_Cons} & @!\verb!{thm_style rhs foldl_Cons}!\\
haftmann@15917
   405
    \verb!\end{tabular}!\\
haftmann@15917
   406
    \verb!\end{center}!
haftmann@15917
   407
  \end{quote}
haftmann@15917
   408
  Note the space between \verb!@! and \verb!{! in the tabular argument.
haftmann@15917
   409
  It prevents Isabelle from interpreting \verb!@ {~~...~~}! 
kleing@16076
   410
  as an antiquotation. The styles \verb!lhs! and \verb!rhs!
haftmann@16040
   411
  extract the left hand side (or right hand side respectivly) from the
kleing@16076
   412
  conclusion of propositions consisting of a binary operator
haftmann@16040
   413
  (e.~g.~@{text "="}, @{text "\<equiv>"}, @{text "<"}).
haftmann@15917
   414
haftmann@16165
   415
  Likewise, \verb!concl! may be used as a style to show just the
kleing@16076
   416
  conclusion of a proposition. For example, take \verb!hd_Cons_tl!:
haftmann@16040
   417
  \begin{center}
haftmann@17031
   418
    @{thm [show_types] hd_Cons_tl}
haftmann@16040
   419
  \end{center}
haftmann@16040
   420
  To print just the conclusion,
haftmann@15917
   421
  \begin{center}
haftmann@17031
   422
    @{thm_style [show_types] concl hd_Cons_tl}
haftmann@15917
   423
  \end{center}
haftmann@16040
   424
  type
haftmann@15917
   425
  \begin{quote}
haftmann@15917
   426
    \verb!\begin{center}!\\
haftmann@17031
   427
    \verb!@!\verb!{thm_style [show_types] concl hd_Cons_tl}!\\
haftmann@15917
   428
    \verb!\end{center}!
haftmann@15917
   429
  \end{quote}
nipkow@17127
   430
  Beware that any options must be placed \emph{before}
haftmann@17031
   431
  the name of the style, as in this example.
haftmann@17031
   432
haftmann@16166
   433
  Further use cases can be found in \S\ref{sec:yourself}.
haftmann@16166
   434
nipkow@15953
   435
  If you are not afraid of ML, you may also define your own styles.
haftmann@15960
   436
  A style is implemented by an ML function of type
haftmann@15960
   437
  \verb!Proof.context -> term -> term!.
haftmann@15960
   438
  Have a look at the following example:
haftmann@15960
   439
haftmann@16040
   440
*}
nipkow@16075
   441
(*<*)
haftmann@16040
   442
setup {*
haftmann@16040
   443
let
haftmann@16040
   444
  fun my_concl ctxt = Logic.strip_imp_concl
wenzelm@18708
   445
  in TermStyle.add_style "my_concl" my_concl
haftmann@16040
   446
end;
haftmann@16040
   447
*}
nipkow@16075
   448
(*>*)
haftmann@16040
   449
text {*
haftmann@16040
   450
haftmann@15917
   451
  \begin{quote}
haftmann@15917
   452
    \verb!setup {!\verb!*!\\
haftmann@15917
   453
    \verb!let!\\
haftmann@16040
   454
    \verb!  fun my_concl ctxt = Logic.strip_imp_concl!\\
wenzelm@18708
   455
    \verb!  in TermStyle.add_style "my_concl" my_concl!\\
haftmann@15917
   456
    \verb!end;!\\
haftmann@15917
   457
    \verb!*!\verb!}!\\
haftmann@15917
   458
  \end{quote}
haftmann@15960
   459
kleing@16076
   460
  \noindent
haftmann@16165
   461
  This example shows how the \verb!concl! style is implemented
kleing@16076
   462
  and may be used as as a ``copy-and-paste'' pattern to write your own styles.
haftmann@15960
   463
kleing@16076
   464
  The code should go into your theory file, separate from the \LaTeX\ text.
haftmann@16040
   465
  The \verb!let! expression avoids polluting the
haftmann@15960
   466
  ML global namespace. Each style receives the current proof context
kleing@16076
   467
  as first argument; this is helpful in situations where the
kleing@16076
   468
  style has some object-logic specific behaviour for example.
haftmann@15960
   469
haftmann@15960
   470
  The mapping from identifier name to the style function
nipkow@17123
   471
  is done by the @{ML TermStyle.add_style} expression which expects the desired
haftmann@15960
   472
  style name and the style function as arguments.
haftmann@15960
   473
  
haftmann@15960
   474
  After this \verb!setup!,
haftmann@16040
   475
  there will be a new style available named \verb!my_concl!, thus allowing
haftmann@16040
   476
  antiquoations like \verb!@!\verb!{thm_style my_concl hd_Cons_tl}!
haftmann@16040
   477
  yielding @{thm_style my_concl hd_Cons_tl}.
haftmann@15917
   478
haftmann@15917
   479
*}
haftmann@15917
   480
nipkow@15337
   481
(*<*)
nipkow@15337
   482
end
nipkow@16175
   483
(*>*)