7 signature BIBTEX = |
7 signature BIBTEX = |
8 sig |
8 sig |
9 val check_database: |
9 val check_database: |
10 Position.T -> string -> (string * Position.T) list * (string * Position.T) list |
10 Position.T -> string -> (string * Position.T) list * (string * Position.T) list |
11 val check_database_output: Position.T -> string -> unit |
11 val check_database_output: Position.T -> string -> unit |
|
12 val check_bibtex_entry: Proof.context -> string * Position.T -> unit |
12 val cite_macro: string Config.T |
13 val cite_macro: string Config.T |
13 val cite_antiquotation: binding -> (Proof.context -> string) -> theory -> theory |
14 val cite_antiquotation: binding -> (Proof.context -> string) -> theory -> theory |
14 end; |
15 end; |
15 |
16 |
16 structure Bibtex: BIBTEX = |
17 structure Bibtex: BIBTEX = |
33 warnings |> List.app (fn (msg, pos) => |
34 warnings |> List.app (fn (msg, pos) => |
34 warning ("Bibtex warning" ^ Position.here pos ^ ":\n " ^ msg)) |
35 warning ("Bibtex warning" ^ Position.here pos ^ ":\n " ^ msg)) |
35 end; |
36 end; |
36 |
37 |
37 |
38 |
|
39 (* check bibtex entry *) |
|
40 |
|
41 fun check_bibtex_entry ctxt (name, pos) = |
|
42 let |
|
43 fun warn () = |
|
44 if Context_Position.is_visible ctxt then |
|
45 warning ("Unknown session context: cannot check Bibtex entry " ^ |
|
46 quote name ^ Position.here pos) |
|
47 else (); |
|
48 in |
|
49 if name = "*" then () |
|
50 else |
|
51 (case Position.id_of pos of |
|
52 NONE => warn () |
|
53 | SOME id => |
|
54 (case \<^scala>\<open>bibtex_session_entries\<close> [id] of |
|
55 [] => warn () |
|
56 | _ :: entries => |
|
57 Completion.check_entity Markup.bibtex_entryN (map (rpair Position.none) entries) |
|
58 ctxt (name, pos) |> ignore)) |
|
59 end; |
|
60 |
|
61 |
38 (* document antiquotations *) |
62 (* document antiquotations *) |
39 |
63 |
40 val cite_macro = Attrib.setup_config_string \<^binding>\<open>cite_macro\<close> (K ""); |
64 val cite_macro = Attrib.setup_config_string \<^binding>\<open>cite_macro\<close> (K ""); |
41 fun get_cite_macro ctxt = Config.get ctxt cite_macro; |
65 fun get_cite_macro ctxt = Config.get ctxt cite_macro; |
42 |
66 |
46 |
70 |
47 local |
71 local |
48 |
72 |
49 val parse_citations = Parse.and_list1 Args.name_position; |
73 val parse_citations = Parse.and_list1 Args.name_position; |
50 |
74 |
51 fun command_theory_name () = |
|
52 let |
|
53 fun err () = error ("Cannot determine command theory name: bad PIDE id"); |
|
54 val res = |
|
55 (case Position.id_of (Position.thread_data ()) of |
|
56 SOME id => \<^scala>\<open>command_theory_name\<close> id |
|
57 | NONE => err ()); |
|
58 in if res = "" then err () else res end; |
|
59 |
|
60 fun theory_name thy = |
|
61 let val name0 = Context.theory_long_name thy; |
|
62 in if name0 = Context.PureN then command_theory_name () else name0 end; |
|
63 |
|
64 fun cite_command ctxt get_kind ((opt_loc, citations), macro_name) = |
75 fun cite_command ctxt get_kind ((opt_loc, citations), macro_name) = |
65 let |
76 let |
66 val loc = the_default Input.empty opt_loc; |
77 val loc = the_default Input.empty opt_loc; |
67 val _ = |
78 val _ = |
68 Context_Position.reports ctxt |
79 Context_Position.reports ctxt |
69 (Document_Output.document_reports loc @ |
80 (Document_Output.document_reports loc @ |
70 map (fn (name, pos) => (pos, Markup.citation name)) citations); |
81 map (fn (name, pos) => (pos, Markup.citation name)) citations); |
71 |
82 val _ = List.app (check_bibtex_entry ctxt) citations; |
72 val thy_name = theory_name (Proof_Context.theory_of ctxt); |
|
73 val bibtex_entries = Resources.theory_bibtex_entries thy_name; |
|
74 val _ = |
|
75 if null bibtex_entries andalso thy_name <> Context.PureN then () |
|
76 else |
|
77 citations |> List.app (fn (name, pos) => |
|
78 if member (op =) bibtex_entries name orelse name = "*" then () |
|
79 else error ("Unknown Bibtex entry " ^ quote name ^ Position.here pos)); |
|
80 |
83 |
81 val kind = if macro_name = "" then get_kind ctxt else macro_name; |
84 val kind = if macro_name = "" then get_kind ctxt else macro_name; |
82 val location = Document_Output.output_document ctxt {markdown = false} loc; |
85 val location = Document_Output.output_document ctxt {markdown = false} loc; |
83 in Latex.cite {kind = kind, citations = citations, location = location} end; |
86 in Latex.cite {kind = kind, citations = citations, location = location} end; |
84 |
87 |