src/Pure/Tools/bibtex.ML
author wenzelm
Sun, 05 Oct 2014 17:58:36 +0200
changeset 58545 30b75b7958d6
parent 58544 340f130b3d38
child 58550 f65911a725ba
permissions -rw-r--r--
citation tooltip/hyperlink based on open buffers with .bib files;

(*  Title:      Pure/Tools/bibtex.ML
    Author:     Makarius

BibTeX support.
*)

signature BIBTEX =
sig
  val cite_macro: string Config.T
end;

structure Bibtex: BIBTEX =
struct

val cite_macro = Attrib.setup_config_string @{binding cite_macro} (K "cite");

val _ =
  Theory.setup
   (Thy_Output.add_option @{binding cite_macro} (Config.put cite_macro) #>
    Thy_Output.antiquotation @{binding cite}
      (Scan.lift
        (Scan.option (Parse.verbatim || Parse.cartouche) --
         Scan.repeat1 (Parse.position Args.name)))
      (fn {context = ctxt, ...} => fn (opt, citations) =>
        let
          val _ =
            Context_Position.reports ctxt
              (map (fn (name, pos) => (pos, Markup.citation name)) citations);
          val opt_arg = (case opt of NONE => "" | SOME s => "[" ^ s ^ "]");
          val arg = "{" ^ space_implode "," (map #1 citations) ^ "}";
        in "\\" ^ Config.get ctxt cite_macro ^ opt_arg ^ arg end));

end;