author | wenzelm |
Thu, 18 Jan 2018 21:41:30 +0100 | |
changeset 67463 | a5ca98950a91 |
parent 67386 | 998e01d6f8fd |
child 69349 | 7cef9e386ffe |
permissions | -rw-r--r-- |
67274 | 1 |
(* Title: Pure/Thy/bibtex.ML |
58544
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
3 |
|
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
4 |
BibTeX support. |
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
5 |
*) |
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
6 |
|
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
7 |
signature BIBTEX = |
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
8 |
sig |
67301 | 9 |
val check_database: |
10 |
Position.T -> string -> (string * Position.T) list * (string * Position.T) list |
|
67275
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
11 |
val check_database_output: Position.T -> string -> unit |
58544
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
12 |
val cite_macro: string Config.T |
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
13 |
end; |
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
14 |
|
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
15 |
structure Bibtex: BIBTEX = |
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
16 |
struct |
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
17 |
|
67275
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
18 |
(* check database *) |
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
19 |
|
67301 | 20 |
type message = string * Position.T; |
67275
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
21 |
|
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
22 |
fun check_database pos0 database = |
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
23 |
Invoke_Scala.method "isabelle.Bibtex.check_database_yxml" database |
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
24 |
|> YXML.parse_body |
67301 | 25 |
|> let open XML.Decode in pair (list (pair string properties)) (list (pair string properties)) end |
26 |
|> (apply2 o map o apsnd) (fn pos => Position.of_properties (pos @ Position.get_props pos0)); |
|
67275
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
27 |
|
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
28 |
fun check_database_output pos0 database = |
67301 | 29 |
let val (errors, warnings) = check_database pos0 database in |
30 |
errors |> List.app (fn (msg, pos) => |
|
67275
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
31 |
Output.error_message ("Bibtex error" ^ Position.here pos ^ ":\n " ^ msg)); |
67301 | 32 |
warnings |> List.app (fn (msg, pos) => |
67275
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
33 |
warning ("Bibtex warning" ^ Position.here pos ^ ":\n " ^ msg)) |
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
34 |
end; |
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
35 |
|
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
36 |
|
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
37 |
(* document antiquotations *) |
5e427586cb57
check bibtex database on ML side -- for semantic PIDE editing;
wenzelm
parents:
67274
diff
changeset
|
38 |
|
67147 | 39 |
val cite_macro = Attrib.setup_config_string \<^binding>\<open>cite_macro\<close> (K "cite"); |
58544
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
40 |
|
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
41 |
val _ = |
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
42 |
Theory.setup |
67386 | 43 |
(Document_Antiquotation.setup_option \<^binding>\<open>cite_macro\<close> (Config.put cite_macro) #> |
67463 | 44 |
Thy_Output.antiquotation_raw \<^binding>\<open>cite\<close> |
58544
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
45 |
(Scan.lift |
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
46 |
(Scan.option (Parse.verbatim || Parse.cartouche) -- |
58550
f65911a725ba
more explicit syntax, to avoid misunderstanding of foo-bar as 3 separate arguments;
wenzelm
parents:
58545
diff
changeset
|
47 |
Parse.and_list1 (Parse.position Args.name))) |
67463 | 48 |
(fn ctxt => fn (opt, citations) => |
58544
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
49 |
let |
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
50 |
val thy = Proof_Context.theory_of ctxt; |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
51 |
val bibtex_entries = Present.get_bibtex_entries thy; |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
52 |
val _ = |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
53 |
if null bibtex_entries andalso Context.theory_name thy <> Context.PureN then () |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
54 |
else |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
55 |
citations |> List.app (fn (name, pos) => |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
56 |
if member (op =) bibtex_entries name then () |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
57 |
else error ("Unknown Bibtex entry " ^ quote name ^ Position.here pos)); |
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
58544
diff
changeset
|
58 |
val _ = |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
58544
diff
changeset
|
59 |
Context_Position.reports ctxt |
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
58544
diff
changeset
|
60 |
(map (fn (name, pos) => (pos, Markup.citation name)) citations); |
58544
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
61 |
val opt_arg = (case opt of NONE => "" | SOME s => "[" ^ s ^ "]"); |
58545
30b75b7958d6
citation tooltip/hyperlink based on open buffers with .bib files;
wenzelm
parents:
58544
diff
changeset
|
62 |
val arg = "{" ^ space_implode "," (map #1 citations) ^ "}"; |
67463 | 63 |
in Latex.string ("\\" ^ Config.get ctxt cite_macro ^ opt_arg ^ arg) end)); |
58544
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
64 |
|
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
65 |
end; |