src/HOL/Library/LaTeXsugar.thy
author wenzelm
Wed Mar 08 10:50:59 2017 +0100 (2017-03-08)
changeset 65151 a7394aa4d21c
parent 63935 aa1fe1103ab8
child 66527 7ca69030a2af
permissions -rw-r--r--
tuned proofs;
     1 (*  Title:      HOL/Library/LaTeXsugar.thy
     2     Author:     Gerwin Klein, Tobias Nipkow, Norbert Schirmer
     3     Copyright   2005 NICTA and TUM
     4 *)
     5 
     6 (*<*)
     7 theory LaTeXsugar
     8 imports Main
     9 begin
    10 
    11 (* LOGIC *)
    12 notation (latex output)
    13   If  ("(\<^latex>\<open>\\textsf{\<close>if\<^latex>\<open>}\<close> (_)/ \<^latex>\<open>\\textsf{\<close>then\<^latex>\<open>}\<close> (_)/ \<^latex>\<open>\\textsf{\<close>else\<^latex>\<open>}\<close> (_))" 10)
    14 
    15 syntax (latex output)
    16 
    17   "_Let"        :: "[letbinds, 'a] => 'a"
    18   ("(\<^latex>\<open>\\textsf{\<close>let\<^latex>\<open>}\<close> (_)/ \<^latex>\<open>\\textsf{\<close>in\<^latex>\<open>}\<close> (_))" 10)
    19 
    20   "_case_syntax":: "['a, cases_syn] => 'b"
    21   ("(\<^latex>\<open>\\textsf{\<close>case\<^latex>\<open>}\<close> _ \<^latex>\<open>\\textsf{\<close>of\<^latex>\<open>}\<close>/ _)" 10)
    22 
    23 
    24 (* SETS *)
    25 
    26 (* empty set *)
    27 notation (latex)
    28   "Set.empty" ("\<emptyset>")
    29 
    30 (* insert *)
    31 translations 
    32   "{x} \<union> A" <= "CONST insert x A"
    33   "{x,y}" <= "{x} \<union> {y}"
    34   "{x,y} \<union> A" <= "{x} \<union> ({y} \<union> A)"
    35   "{x}" <= "{x} \<union> \<emptyset>"
    36 
    37 (* set comprehension *)
    38 syntax (latex output)
    39   "_Collect" :: "pttrn => bool => 'a set"              ("(1{_ | _})")
    40   "_CollectIn" :: "pttrn => 'a set => bool => 'a set"   ("(1{_ \<in> _ | _})")
    41 translations
    42   "_Collect p P"      <= "{p. P}"
    43   "_Collect p P"      <= "{p|xs. P}"
    44   "_CollectIn p A P"  <= "{p : A. P}"
    45 
    46 (* card *)
    47 notation (latex output)
    48   card  ("|_|")
    49 
    50 (* LISTS *)
    51 
    52 (* Cons *)
    53 notation (latex)
    54   Cons  ("_ \<cdot>/ _" [66,65] 65)
    55 
    56 (* length *)
    57 notation (latex output)
    58   length  ("|_|")
    59 
    60 (* nth *)
    61 notation (latex output)
    62   nth  ("_\<^latex>\<open>\\ensuremath{_{[\\mathit{\<close>_\<^latex>\<open>}]}}\<close>" [1000,0] 1000)
    63 
    64 (* DUMMY *)
    65 consts DUMMY :: 'a ("\<^latex>\<open>\\_\<close>")
    66 
    67 (* THEOREMS *)
    68 notation (Rule output)
    69   Pure.imp  ("\<^latex>\<open>\\mbox{}\\inferrule{\\mbox{\<close>_\<^latex>\<open>}}\<close>\<^latex>\<open>{\\mbox{\<close>_\<^latex>\<open>}}\<close>")
    70 
    71 syntax (Rule output)
    72   "_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop"
    73   ("\<^latex>\<open>\\mbox{}\\inferrule{\<close>_\<^latex>\<open>}\<close>\<^latex>\<open>{\\mbox{\<close>_\<^latex>\<open>}}\<close>")
    74 
    75   "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" 
    76   ("\<^latex>\<open>\\mbox{\<close>_\<^latex>\<open>}\\\\\<close>/ _")
    77 
    78   "_asm" :: "prop \<Rightarrow> asms" ("\<^latex>\<open>\\mbox{\<close>_\<^latex>\<open>}\<close>")
    79 
    80 notation (Axiom output)
    81   "Trueprop"  ("\<^latex>\<open>\\mbox{}\\inferrule{\\mbox{}}{\\mbox{\<close>_\<^latex>\<open>}}\<close>")
    82 
    83 notation (IfThen output)
    84   Pure.imp  ("\<^latex>\<open>{\\normalsize{}\<close>If\<^latex>\<open>\\,}\<close> _/ \<^latex>\<open>{\\normalsize \\,\<close>then\<^latex>\<open>\\,}\<close>/ _.")
    85 syntax (IfThen output)
    86   "_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop"
    87   ("\<^latex>\<open>{\\normalsize{}\<close>If\<^latex>\<open>\\,}\<close> _ /\<^latex>\<open>{\\normalsize \\,\<close>then\<^latex>\<open>\\,}\<close>/ _.")
    88   "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" ("\<^latex>\<open>\\mbox{\<close>_\<^latex>\<open>}\<close> /\<^latex>\<open>{\\normalsize \\,\<close>and\<^latex>\<open>\\,}\<close>/ _")
    89   "_asm" :: "prop \<Rightarrow> asms" ("\<^latex>\<open>\\mbox{\<close>_\<^latex>\<open>}\<close>")
    90 
    91 notation (IfThenNoBox output)
    92   Pure.imp  ("\<^latex>\<open>{\\normalsize{}\<close>If\<^latex>\<open>\\,}\<close> _/ \<^latex>\<open>{\\normalsize \\,\<close>then\<^latex>\<open>\\,}\<close>/ _.")
    93 syntax (IfThenNoBox output)
    94   "_bigimpl" :: "asms \<Rightarrow> prop \<Rightarrow> prop"
    95   ("\<^latex>\<open>{\\normalsize{}\<close>If\<^latex>\<open>\\,}\<close> _ /\<^latex>\<open>{\\normalsize \\,\<close>then\<^latex>\<open>\\,}\<close>/ _.")
    96   "_asms" :: "prop \<Rightarrow> asms \<Rightarrow> asms" ("_ /\<^latex>\<open>{\\normalsize \\,\<close>and\<^latex>\<open>\\,}\<close>/ _")
    97   "_asm" :: "prop \<Rightarrow> asms" ("_")
    98 
    99 setup\<open>
   100   let
   101     fun pretty ctxt c =
   102       let val tc = Proof_Context.read_const {proper = true, strict = false} ctxt c
   103       in Pretty.block [Thy_Output.pretty_term ctxt tc, Pretty.str " ::",
   104             Pretty.brk 1, Syntax.pretty_typ ctxt (fastype_of tc)]
   105       end
   106   in
   107     Thy_Output.antiquotation @{binding "const_typ"}
   108      (Scan.lift Args.embedded_inner_syntax)
   109        (fn {source = src, context = ctxt, ...} => fn arg =>
   110           Thy_Output.output ctxt
   111             (Thy_Output.maybe_pretty_source pretty ctxt src [arg]))
   112   end;
   113 \<close>
   114 
   115 setup\<open>
   116 let
   117   fun dummy_pats (wrap $ (eq $ lhs $ rhs)) =
   118     let
   119       val rhs_vars = Term.add_vars rhs [];
   120       fun dummy (v as Var (ixn as (_, T))) =
   121             if member (op = ) rhs_vars ixn then v else Const (@{const_name DUMMY}, T)
   122         | dummy (t $ u) = dummy t $ dummy u
   123         | dummy (Abs (n, T, b)) = Abs (n, T, dummy b)
   124         | dummy t = t;
   125     in wrap $ (eq $ dummy lhs $ rhs) end
   126 in
   127   Term_Style.setup @{binding dummy_pats} (Scan.succeed (K dummy_pats))
   128 end
   129 \<close>
   130 
   131 end
   132 (*>*)