From 005922ffda2a779121a47bf80d0274f5e177a80f Mon Sep 17 00:00:00 2001 From: Burkhart Wolff Date: Wed, 23 Dec 2020 09:41:26 +0100 Subject: [PATCH] built in syntactic checks for trimming macros --- .../Isabelle_DOF-Manual/00_Frontmatter.thy | 2 +- .../scholarly_paper/scholarly_paper.thy | 42 ++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/examples/technical_report/Isabelle_DOF-Manual/00_Frontmatter.thy b/examples/technical_report/Isabelle_DOF-Manual/00_Frontmatter.thy index ca125b1..c6cb725 100755 --- a/examples/technical_report/Isabelle_DOF-Manual/00_Frontmatter.thy +++ b/examples/technical_report/Isabelle_DOF-Manual/00_Frontmatter.thy @@ -33,7 +33,7 @@ define_shortcut* TeXLive \ \\TeXLive\ text\Note that these setups assume that the associated \<^LaTeX> macros are defined, \<^eg>, in the document prelude. \ -define_macro* index \ \\index{\ _ \}\ +define_macro* index \ \\index{\ _ \}\ define_macro* bindex \ \\bindex{\ _ \}\ diff --git a/src/ontologies/scholarly_paper/scholarly_paper.thy b/src/ontologies/scholarly_paper/scholarly_paper.thy index 535107d..67ad50c 100755 --- a/src/ontologies/scholarly_paper/scholarly_paper.thy +++ b/src/ontologies/scholarly_paper/scholarly_paper.thy @@ -479,16 +479,46 @@ define_shortcut* eg \ \\eg\ (* Latin: „exemp ie \ \\ie\ (* Latin: „id est“ meaning „that is to say“. *) etc \ \\etc\ (* Latin : „et cetera“ meaning „et cetera“ *) -subsection\Layout Trimming Commands\ +subsection\Layout Trimming Commands (with syntactic checks)\ -define_macro* hs \ \\hspace{\ _ \}\ -define_macro* vs \ \\vspace{\ _ \}\ +ML\ +local -(* setup\ DOF_lib.define_macro \<^binding>\hs\ "\\hspace{" "}" (K(K())) \ *) -ML\ Parse.real \ +val scan_cm = Scan.ahead (Basic_Symbol_Pos.$$$ "c" |-- Basic_Symbol_Pos.$$$ "m" ) ; +val scan_pt = Scan.ahead (Basic_Symbol_Pos.$$$ "p" |-- Basic_Symbol_Pos.$$$ "t" ) ; -setup\ DOF_lib.define_macro \<^binding>\vs2\ "\\vspace{" "}" (fn ctxt => fn src => ()) \ +val scan_blank = Scan.repeat (Basic_Symbol_Pos.$$$ " " + || Basic_Symbol_Pos.$$$ "\t" + || Basic_Symbol_Pos.$$$ "\n"); +val scan_latex_measure = (scan_blank + |-- Scan.option (Basic_Symbol_Pos.$$$ "-") + |-- Symbol_Pos.scan_nat + |-- (Scan.option ((Basic_Symbol_Pos.$$$ ".") |-- Symbol_Pos.scan_nat)) + |-- scan_blank + |-- (scan_cm || scan_pt) + |-- scan_blank + ); +in + +fun check_latex_measure _ src = + let val _ = ((Scan.catch scan_latex_measure (Symbol_Pos.explode(Input.source_content src))) + handle Fail _ => error ("syntax error in LaTeX measure") ) + in () end +end + +\ + +ML\ (* test *) check_latex_measure @{context} (Input.string "-3.14 cm") \ + +define_macro* hs \ \\hspace{\ _ \}\ (check_latex_measure) +define_macro* vs \ \\vspace{\ _ \}\ (check_latex_measure) + + + +setup\ DOF_lib.define_macro \<^binding>\vs2\ "\\vspace{" "}" (check_latex_measure) \ + +text\ \<^vs2>\-3.14cm\\ define_shortcut* clearpage \ \\clearpage{}\