author | wenzelm |
Sun, 21 Aug 2022 11:48:14 +0200 | |
changeset 75939 | 87f0adcb7e10 |
parent 74887 | 56247fdb8bbb |
child 76955 | 3f25c28c4257 |
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 = |
72194 | 23 |
\<^scala>\<open>bibtex_check_database\<close> database |
67275
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) #> |
73761 | 44 |
Document_Output.antiquotation_raw \<^binding>\<open>cite\<close> |
74887 | 45 |
(Scan.lift (Scan.option Parse.cartouche -- Parse.and_list1 Args.name_position)) |
67463 | 46 |
(fn ctxt => fn (opt, citations) => |
58544
340f130b3d38
bibtex support in ML: document antiquotation @{cite} with markup;
wenzelm
parents:
diff
changeset
|
47 |
let |
73148
5f49f1149c1c
clarified reports before errors: support completion of bibtex entries in Isabelle/Scala (amending d01ea9e3bd2d);
wenzelm
parents:
73147
diff
changeset
|
48 |
val _ = |
5f49f1149c1c
clarified reports before errors: support completion of bibtex entries in Isabelle/Scala (amending d01ea9e3bd2d);
wenzelm
parents:
73147
diff
changeset
|
49 |
Context_Position.reports ctxt |
5f49f1149c1c
clarified reports before errors: support completion of bibtex entries in Isabelle/Scala (amending d01ea9e3bd2d);
wenzelm
parents:
73147
diff
changeset
|
50 |
(map (fn (name, pos) => (pos, Markup.citation name)) citations); |
5f49f1149c1c
clarified reports before errors: support completion of bibtex entries in Isabelle/Scala (amending d01ea9e3bd2d);
wenzelm
parents:
73147
diff
changeset
|
51 |
|
73147 | 52 |
val thy_name = Context.theory_long_name (Proof_Context.theory_of ctxt); |
53 |
val bibtex_entries = Resources.theory_bibtex_entries thy_name; |
|
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
54 |
val _ = |
73147 | 55 |
if null bibtex_entries andalso thy_name <> Context.PureN then () |
67297
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
56 |
else |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
57 |
citations |> List.app (fn (name, pos) => |
86a099f896fc
formal check of @{cite} bibtex entries -- only in batch-mode session builds;
wenzelm
parents:
67280
diff
changeset
|
58 |
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
|
59 |
else error ("Unknown Bibtex entry " ^ quote name ^ Position.here pos)); |
73148
5f49f1149c1c
clarified reports before errors: support completion of bibtex entries in Isabelle/Scala (amending d01ea9e3bd2d);
wenzelm
parents:
73147
diff
changeset
|
60 |
|
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; |