# HG changeset patch # User wenzelm # Date 1447178609 -3600 # Node ID 34978e1b234ff28343910a4e1473a0acecac7fd6 # Parent e4194168a1eb3d8106c164d7e16f8fa1d0a07786 added document antiquotation @{theory_text}; tuned document; diff -r e4194168a1eb -r 34978e1b234f NEWS --- a/NEWS Tue Nov 10 16:03:59 2015 +0100 +++ b/NEWS Tue Nov 10 19:03:29 2015 +0100 @@ -91,6 +91,9 @@ standard Isabelle fonts provide glyphs to render important control symbols, e.g. "\<^verbatim>", "\<^emph>", "\<^bold>". +* Antiquotation @{theory_text} prints uninterpreted theory source text +(outer syntax with command keywords etc.). + * Antiquotations @{noindent}, @{smallskip}, @{medskip}, @{bigskip} with corresponding control symbols \<^noindent>, \<^smallskip>, \<^medskip>, \<^bigskip> specify spacing formally, using standard LaTeX macros of the same names. diff -r e4194168a1eb -r 34978e1b234f src/Doc/Isar_Ref/Document_Preparation.thy --- a/src/Doc/Isar_Ref/Document_Preparation.thy Tue Nov 10 16:03:59 2015 +0100 +++ b/src/Doc/Isar_Ref/Document_Preparation.thy Tue Nov 10 19:03:29 2015 +0100 @@ -110,40 +110,35 @@ @{command_def "print_antiquotations"}\\<^sup>*\ & : & \context \\ \\ \end{matharray} - The overall content of an Isabelle/Isar theory may alternate between - formal and informal text. The main body consists of formal - specification and proof commands, interspersed with markup commands - (\secref{sec:markup}) or document comments (\secref{sec:comments}). - The argument of markup commands quotes informal text to be printed - in the resulting document, but may again refer to formal entities - via \<^emph>\document antiquotations\. + The overall content of an Isabelle/Isar theory may alternate between formal + and informal text. The main body consists of formal specification and proof + commands, interspersed with markup commands (\secref{sec:markup}) or + document comments (\secref{sec:comments}). The argument of markup commands + quotes informal text to be printed in the resulting document, but may again + refer to formal entities via \<^emph>\document antiquotations\. For example, embedding \<^verbatim>\@{term [show_types] "f x = a + x"}\ within a text block makes \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. - Antiquotations usually spare the author tedious typing of logical - entities in full detail. Even more importantly, some degree of - consistency-checking between the main body of formal text and its - informal explanation is achieved, since terms and types appearing in - antiquotations are checked within the current theory or proof - context. + Antiquotations usually spare the author tedious typing of logical entities + in full detail. Even more importantly, some degree of consistency-checking + between the main body of formal text and its informal explanation is + achieved, since terms and types appearing in antiquotations are checked + within the current theory or proof context. - \<^medskip> Antiquotations are in general written as \<^verbatim>\@{\\name\~\<^verbatim>\[\\options\\<^verbatim>\]\~\arguments\\<^verbatim>\}\. - The short form \<^verbatim>\\\\<^verbatim>\<^\\name\\<^verbatim>\>\\\argument_content\\ (without - surrounding \<^verbatim>\@{\\\\\<^verbatim>\}\) works for a single - argument that is a cartouche. - - A cartouche without special decoration is equivalent to - \<^verbatim>\\<^cartouche>\\\argument_content\\, which is equivalent to - \<^verbatim>\@{cartouche\~\\argument_content\\\<^verbatim>\}\. The special name + \<^medskip> + Antiquotations are in general written as + \<^verbatim>\@{\\name\~\<^verbatim>\[\\options\\<^verbatim>\]\~\arguments\\<^verbatim>\}\. The short form + \<^verbatim>\\\\<^verbatim>\<^\\name\\<^verbatim>\>\\\argument_content\\ (without surrounding \<^verbatim>\@{\\\\\<^verbatim>\}\) + works for a single argument that is a cartouche. A cartouche without special + decoration is equivalent to \<^verbatim>\\<^cartouche>\\\argument_content\\, which is + equivalent to \<^verbatim>\@{cartouche\~\\argument_content\\\<^verbatim>\}\. The special name @{antiquotation_def cartouche} is defined in the context: Isabelle/Pure introduces that as an alias to @{antiquotation_ref text} (see below). Consequently, \\foo_bar + baz \ bazar\\ prints literal quasi-formal text - (unchecked). - - A control symbol \<^verbatim>\\\\<^verbatim>\<^\\name\\<^verbatim>\>\ within the body text, but without a - subsequent cartouche, is equivalent to \<^verbatim>\@{\\name\\<^verbatim>\}\. + (unchecked). A control symbol \<^verbatim>\\\\<^verbatim>\<^\\name\\<^verbatim>\>\ within the body text, but + without a subsequent cartouche, is equivalent to \<^verbatim>\@{\\name\\<^verbatim>\}\. \begingroup \def\isasymcontrolstart{\isatt{\isacharbackslash\isacharless\isacharcircum}} @@ -160,13 +155,14 @@ \} \endgroup - Note that the syntax of antiquotations may \<^emph>\not\ include source - comments \<^verbatim>\(*\~\\\~\<^verbatim>\*)\ nor verbatim text \<^verbatim>\{*\~\\\~\<^verbatim>\*}\. + Note that the syntax of antiquotations may \<^emph>\not\ include source comments + \<^verbatim>\(*\~\\\~\<^verbatim>\*)\ nor verbatim text \<^verbatim>\{*\~\\\~\<^verbatim>\*}\. %% FIXME less monolithic presentation, move to individual sections!? @{rail \ @{syntax_def antiquotation_body}: - (@@{antiquotation text} | @@{antiquotation cartouche}) options @{syntax text} | + (@@{antiquotation text} | @@{antiquotation cartouche} | @@{antiquotation theory_text}) + options @{syntax text} | @@{antiquotation theory} options @{syntax name} | @@{antiquotation thm} options styles @{syntax thmrefs} | @@{antiquotation lemma} options @{syntax prop} @'by' @{syntax method} @{syntax method}? | @@ -206,113 +202,103 @@ @@{command print_antiquotations} ('!'?) \} - \<^descr> \@{text s}\ prints uninterpreted source text \s\. This is particularly useful to print portions of text according - to the Isabelle document style, without demanding well-formedness, - e.g.\ small pieces of terms that should not be parsed or - type-checked yet. + \<^descr> \@{text s}\ prints uninterpreted source text \s\, i.e.\ inner syntax. This + is particularly useful to print portions of text according to the Isabelle + document style, without demanding well-formedness, e.g.\ small pieces of + terms that should not be parsed or type-checked yet. It is also possible to write this in the short form \\s\\ without any further decoration. - \<^descr> \@{theory A}\ prints the name \A\, which is - guaranteed to refer to a valid ancestor theory in the current - context. + \<^descr> \@{theory_text s}\ prints uninterpreted theory source text \s\, i.e.\ + outer syntax with command keywords and other tokens. - \<^descr> \@{thm a\<^sub>1 \ a\<^sub>n}\ prints theorems \a\<^sub>1 \ a\<^sub>n\. - Full fact expressions are allowed here, including attributes - (\secref{sec:syn-att}). + \<^descr> \@{theory A}\ prints the name \A\, which is guaranteed to refer to a valid + ancestor theory in the current context. + + \<^descr> \@{thm a\<^sub>1 \ a\<^sub>n}\ prints theorems \a\<^sub>1 \ a\<^sub>n\. Full fact expressions are + allowed here, including attributes (\secref{sec:syn-att}). \<^descr> \@{prop \}\ prints a well-typed proposition \\\. - \<^descr> \@{lemma \ by m}\ proves a well-typed proposition - \\\ by method \m\ and prints the original \\\. + \<^descr> \@{lemma \ by m}\ proves a well-typed proposition \\\ by method \m\ and + prints the original \\\. \<^descr> \@{term t}\ prints a well-typed term \t\. - \<^descr> \@{value t}\ evaluates a term \t\ and prints - its result, see also @{command_ref (HOL) value}. + \<^descr> \@{value t}\ evaluates a term \t\ and prints its result, see also + @{command_ref (HOL) value}. - \<^descr> \@{term_type t}\ prints a well-typed term \t\ - annotated with its type. + \<^descr> \@{term_type t}\ prints a well-typed term \t\ annotated with its type. - \<^descr> \@{typeof t}\ prints the type of a well-typed term - \t\. + \<^descr> \@{typeof t}\ prints the type of a well-typed term \t\. - \<^descr> \@{const c}\ prints a logical or syntactic constant - \c\. + \<^descr> \@{const c}\ prints a logical or syntactic constant \c\. - \<^descr> \@{abbrev c x\<^sub>1 \ x\<^sub>n}\ prints a constant abbreviation - \c x\<^sub>1 \ x\<^sub>n \ rhs\ as defined in the current context. + \<^descr> \@{abbrev c x\<^sub>1 \ x\<^sub>n}\ prints a constant abbreviation \c x\<^sub>1 \ x\<^sub>n \ rhs\ + as defined in the current context. \<^descr> \@{typ \}\ prints a well-formed type \\\. - \<^descr> \@{type \}\ prints a (logical or syntactic) type - constructor \\\. + \<^descr> \@{type \}\ prints a (logical or syntactic) type constructor \\\. \<^descr> \@{class c}\ prints a class \c\. - \<^descr> \@{goals}\ prints the current \<^emph>\dynamic\ goal - state. This is mainly for support of tactic-emulation scripts - within Isar. Presentation of goal states does not conform to the - idea of human-readable proof documents! + \<^descr> \@{goals}\ prints the current \<^emph>\dynamic\ goal state. This is mainly for + support of tactic-emulation scripts within Isar. Presentation of goal states + does not conform to the idea of human-readable proof documents! - When explaining proofs in detail it is usually better to spell out - the reasoning via proper Isar proof commands, instead of peeking at - the internal machine configuration. + When explaining proofs in detail it is usually better to spell out the + reasoning via proper Isar proof commands, instead of peeking at the internal + machine configuration. - \<^descr> \@{subgoals}\ is similar to \@{goals}\, but - does not print the main goal. + \<^descr> \@{subgoals}\ is similar to \@{goals}\, but does not print the main goal. - \<^descr> \@{prf a\<^sub>1 \ a\<^sub>n}\ prints the (compact) proof terms - corresponding to the theorems \a\<^sub>1 \ a\<^sub>n\. Note that this - requires proof terms to be switched on for the current logic - session. + \<^descr> \@{prf a\<^sub>1 \ a\<^sub>n}\ prints the (compact) proof terms corresponding to the + theorems \a\<^sub>1 \ a\<^sub>n\. Note that this requires proof terms to be switched on + for the current logic session. - \<^descr> \@{full_prf a\<^sub>1 \ a\<^sub>n}\ is like \@{prf a\<^sub>1 \ - a\<^sub>n}\, but prints the full proof terms, i.e.\ also displays - information omitted in the compact proof term, which is denoted by - ``\_\'' placeholders there. + \<^descr> \@{full_prf a\<^sub>1 \ a\<^sub>n}\ is like \@{prf a\<^sub>1 \ a\<^sub>n}\, but prints the full + proof terms, i.e.\ also displays information omitted in the compact proof + term, which is denoted by ``\_\'' placeholders there. - \<^descr> \@{ML s}\, \@{ML_op s}\, \@{ML_type - s}\, \@{ML_structure s}\, and \@{ML_functor s}\ - check text \s\ as ML value, infix operator, type, structure, - and functor respectively. The source is printed verbatim. + \<^descr> \@{ML s}\, \@{ML_op s}\, \@{ML_type s}\, \@{ML_structure s}\, and + \@{ML_functor s}\ check text \s\ as ML value, infix operator, type, + structure, and functor respectively. The source is printed verbatim. - \<^descr> \@{emph s}\ prints document source recursively, with {\LaTeX} - markup \<^verbatim>\\emph{\\\\\<^verbatim>\}\. + \<^descr> \@{emph s}\ prints document source recursively, with {\LaTeX} markup + \<^verbatim>\\emph{\\\\\<^verbatim>\}\. - \<^descr> \@{bold s}\ prints document source recursively, with {\LaTeX} - markup \<^verbatim>\\textbf{\\\\\<^verbatim>\}\. + \<^descr> \@{bold s}\ prints document source recursively, with {\LaTeX} markup + \<^verbatim>\\textbf{\\\\\<^verbatim>\}\. - \<^descr> \@{verbatim s}\ prints uninterpreted source text literally - as ASCII characters, using some type-writer font style. + \<^descr> \@{verbatim s}\ prints uninterpreted source text literally as ASCII + characters, using some type-writer font style. - \<^descr> \@{file path}\ checks that \path\ refers to a - file (or directory) and prints it verbatim. + \<^descr> \@{file path}\ checks that \path\ refers to a file (or directory) and + prints it verbatim. - \<^descr> \@{file_unchecked path}\ is like \@{file - path}\, but does not check the existence of the \path\ - within the file-system. + \<^descr> \@{file_unchecked path}\ is like \@{file path}\, but does not check the + existence of the \path\ within the file-system. - \<^descr> \@{url name}\ produces markup for the given URL, which - results in an active hyperlink within the text. + \<^descr> \@{url name}\ produces markup for the given URL, which results in an + active hyperlink within the text. - \<^descr> \@{cite name}\ produces a citation \<^verbatim>\\cite{name}\ in {\LaTeX}, - where the name refers to some Bib{\TeX} database entry. + \<^descr> \@{cite name}\ produces a citation \<^verbatim>\\cite{name}\ in {\LaTeX}, where the + name refers to some Bib{\TeX} database entry. - The variant \@{cite \opt\ name}\ produces \<^verbatim>\\cite[opt]{name}\ with - some free-form optional argument. Multiple names - are output with commas, e.g. \@{cite foo \ bar}\ becomes - \<^verbatim>\\cite{foo,bar}\. + The variant \@{cite \opt\ name}\ produces \<^verbatim>\\cite[opt]{name}\ with some + free-form optional argument. Multiple names are output with commas, e.g. + \@{cite foo \ bar}\ becomes \<^verbatim>\\cite{foo,bar}\. The {\LaTeX} macro name is determined by the antiquotation option @{antiquotation_option_def cite_macro}, or the configuration option - @{attribute cite_macro} in the context. For example, \@{cite - [cite_macro = nocite] foobar}\ produces \<^verbatim>\\nocite{foobar}\. + @{attribute cite_macro} in the context. For example, \@{cite [cite_macro = + nocite] foobar}\ produces \<^verbatim>\\nocite{foobar}\. - \<^descr> @{command "print_antiquotations"} prints all document antiquotations - that are defined in the current context; the ``\!\'' option - indicates extra verbosity. + \<^descr> @{command "print_antiquotations"} prints all document antiquotations that + are defined in the current context; the ``\!\'' option indicates extra + verbosity. \ diff -r e4194168a1eb -r 34978e1b234f src/Pure/Isar/token.ML --- a/src/Pure/Isar/token.ML Tue Nov 10 16:03:59 2015 +0100 +++ b/src/Pure/Isar/token.ML Tue Nov 10 19:03:29 2015 +0100 @@ -89,6 +89,8 @@ val pretty_value: Proof.context -> T -> Pretty.T val pretty_src: Proof.context -> src -> Pretty.T val ident_or_symbolic: string -> bool + val source': bool -> Keyword.keywords -> (Symbol_Pos.T, 'a) Source.source -> + (T, (Symbol_Pos.T, 'a) Source.source) Source.source val source_proper: (T, 'a) Source.source -> (T, (T, 'a) Source.source) Source.source val source: Keyword.keywords -> Position.T -> (Symbol.symbol, 'a) Source.source -> (T, diff -r e4194168a1eb -r 34978e1b234f src/Pure/PIDE/markup.ML --- a/src/Pure/PIDE/markup.ML Tue Nov 10 16:03:59 2015 +0100 +++ b/src/Pure/PIDE/markup.ML Tue Nov 10 19:03:29 2015 +0100 @@ -28,6 +28,7 @@ val is_delimited: Properties.T -> bool val language: {name: string, symbols: bool, antiquotes: bool, delimited: bool} -> T val language': {name: string, symbols: bool, antiquotes: bool} -> bool -> T + val language_outer: bool -> T val language_method: T val language_attribute: T val language_sort: bool -> T @@ -299,6 +300,7 @@ fun language' {name, symbols, antiquotes} delimited = language {name = name, symbols = symbols, antiquotes = antiquotes, delimited = delimited}; +val language_outer = language' {name = "", symbols = true, antiquotes = false}; val language_method = language {name = "method", symbols = true, antiquotes = false, delimited = false}; val language_attribute = diff -r e4194168a1eb -r 34978e1b234f src/Pure/Thy/thy_output.ML --- a/src/Pure/Thy/thy_output.ML Tue Nov 10 16:03:59 2015 +0100 +++ b/src/Pure/Thy/thy_output.ML Tue Nov 10 19:03:29 2015 +0100 @@ -650,6 +650,29 @@ end; +(* theory text with tokens (unchecked) *) + +val _ = + Theory.setup + (antiquotation @{binding theory_text} (Scan.lift Args.text_input) + (fn {context = ctxt, ...} => fn source => + let + val _ = + Context_Position.report ctxt (Input.pos_of source) + (Markup.language_outer (Input.is_delimited source)); + + val keywords = Thy_Header.get_keywords' ctxt; + val toks = + Source.of_list (Input.source_explode source) + |> Token.source' true keywords + |> Source.exhaust; + val _ = Context_Position.reports_text ctxt (maps (Token.reports keywords) toks); + in + implode (map Latex.output_token toks) + |> (if Config.get ctxt display then Latex.environment "isabelle" else enclose "\\isa{" "}") + end)); + + (* basic entities *) local