new antiquotation const_typ
authornipkow
Fri, 28 Sep 2012 08:39:48 +0200
changeset 49628 8262d35eff20
parent 49627 34ada66545ca
child 49629 99700c4e0b33
new antiquotation const_typ
src/Doc/LaTeXsugar/Sugar.thy
src/HOL/Library/LaTeXsugar.thy
--- a/src/Doc/LaTeXsugar/Sugar.thy	Fri Sep 28 08:09:28 2012 +0200
+++ b/src/Doc/LaTeXsugar/Sugar.thy	Fri Sep 28 08:39:48 2012 +0200
@@ -525,6 +525,16 @@
 \end{quote}
 The \texttt{isabelle} environment is the one defined in the standard file
 \texttt{isabelle.sty} which most likely you are loading anyway.
+
+
+\section{Antiquotation}
+
+You want to show a constant and its type? Instead of going
+\verb!@!\verb!{const myconst}! \verb!@!\verb!{text "::"}! \verb!@!\verb!{typeof myconst}!,
+you can just write \verb!@!\verb!{const_typ myconst}! using the new antiquotation
+\texttt{const\_typ} defined in \texttt{LaTeXsugar}. For example,
+\verb!@!\verb!{const_typ length}! produces @{const_typ length}.
+
 *}
 
 (*<*)
--- a/src/HOL/Library/LaTeXsugar.thy	Fri Sep 28 08:09:28 2012 +0200
+++ b/src/HOL/Library/LaTeXsugar.thy	Fri Sep 28 08:39:48 2012 +0200
@@ -97,5 +97,21 @@
   "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" ("_ /\<^raw:{\normalsize \,>and\<^raw:\,}>/ _")
   "_asm" :: "prop \<Rightarrow> asms" ("_")
 
+setup{*
+  let
+    fun pretty ctxt c =
+      let val tc = Proof_Context.read_const_proper ctxt false c
+      in Pretty.block [Thy_Output.pretty_term ctxt tc, Pretty.str " ::",
+            Pretty.brk 1, Syntax.pretty_typ ctxt (fastype_of tc)]
+      end
+  in
+    Thy_Output.antiquotation @{binding "const_typ"}
+     (Scan.lift Args.name_source)
+       (fn {source = src, context = ctxt, ...} => fn arg =>
+          Thy_Output.output ctxt
+            (Thy_Output.maybe_pretty_source pretty ctxt src [arg]))
+  end;
+*}
+
 end
 (*>*)
\ No newline at end of file