Here, we convert nodes and docstrings to LaTeX. The main difficulty is converting Markdown to LaTeX, which we describe below.
Equations
Instances For
We convert docstrings of declarations and modules to LaTeX. Besides the usual Markdown features, we also support citations using square brackets and references using inline code, by having custom commands and postprocessing steps, as follows:
- Using MD4Lean, we parse the markdown.
- If possible, we convert bracketed citations (e.g. [taylorwiles]) to \cite{taylorwiles} commands.
- If possible, we convert inline code with a constant (e.g.
abc
) to \ref{abc} commands. - We convert the markdown to LaTeX macro definitions as output.
TODO: Support doc-gen4 style named citations like [abc][def].
The output provides the following macros:
\inputleannode{name}
: Inputs the theorem or definition with Lean namename
.\inputleanmodule{Module}
: Inputs the entire module (containing nodes and module docstrings) with module nameModule
.s
The long-term goal for blueprint-gen is to migrate to Verso and not have to output to LaTeX at all. Here, this would mean using docstring parsing from Verso instead (which similarly uses MD4Lean to parse the docstrings), and it has support for elaborating code blocks. However, AFAIK it currently does not support citations in docstrings.
Escapes a string in LaTeX for all LaTeX environments (text, math, leancode, links, etc.).
Equations
- BlueprintGen.escapeForLatexBasic s = (s.replace "#" "\\#").replace "%" "\\%"
Instances For
Escapes a string in LaTeX for text.
Equations
- BlueprintGen.escapeForLatexText s = ((BlueprintGen.escapeForLatexBasic s).replace "_" "\\_").replace "^" "\\^{}"
Instances For
Escape #
and convert brackets [taylorwiles]
to \cite{taylorwiles}
commands.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- BlueprintGen.removeNameFirstComponent (Lean.Name.anonymous.str str) = some Lean.Name.anonymous
- BlueprintGen.removeNameFirstComponent (Lean.Name.anonymous.num i) = some Lean.Name.anonymous
- BlueprintGen.removeNameFirstComponent (p.str s) = Option.map (fun (p : Lean.Name) => p.str s) (BlueprintGen.removeNameFirstComponent p)
- BlueprintGen.removeNameFirstComponent (p.num i) = Option.map (fun (p : Lean.Name) => p.num i) (BlueprintGen.removeNameFirstComponent p)
- BlueprintGen.removeNameFirstComponent Lean.Name.anonymous = none
Instances For
Equations
Instances For
Parse and convert markdown to LaTeX using MD4Lean with postprocessing steps as above.
Equations
- BlueprintGen.markdownToLatex markdown = match BlueprintGen.parseMarkdown markdown with | none => pure markdown | some doc => BlueprintGen.markdownToLatex.documentToLatex doc
Instances For
Equations
- BlueprintGen.markdownToLatex.documentToLatex doc = do let __do_lift ← Array.mapM BlueprintGen.markdownToLatex.blockToLatex doc.blocks pure ("\n\n".intercalate __do_lift.toList)
Instances For
Equations
- BlueprintGen.markdownToLatex.attrTextToLatex (MD4Lean.AttrText.normal content) = BlueprintGen.escapeForLatexBasic content
- BlueprintGen.markdownToLatex.attrTextToLatex (MD4Lean.AttrText.entity content) = BlueprintGen.escapeForLatexBasic content
- BlueprintGen.markdownToLatex.attrTextToLatex MD4Lean.AttrText.nullchar = ""
Instances For
Equations
- BlueprintGen.moduleToRelPath module ext = Lean.modToFilePath { toString := "module" } module ext
Instances For
Equations
- BlueprintGen.libraryToRelPath library ext = (System.mkFilePath ["library", library.toString false]).addExtension ext
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
- (BlueprintGen.BlueprintContent.node n).toLatex = pure ("\\inputleannode{" ++ n.name.toString ++ "}")
- (BlueprintGen.BlueprintContent.modDoc d).toLatex = BlueprintGen.markdownToLatex d.doc
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Convert imported module to LaTeX.
Equations
- BlueprintGen.moduleToLatexHeader module = do let contents ← BlueprintGen.getBlueprintContents module BlueprintGen.moduleToLatexHeaderAux✝ module contents
Instances For
Convert current module to LaTeX (for debugging).
Equations
- BlueprintGen.mainModuleToLatexHeader = do let contents ← BlueprintGen.getMainModuleBlueprintContents let __do_lift ← Lean.getMainModule BlueprintGen.moduleToLatexHeaderAux✝ __do_lift contents
Instances For
Shows the blueprint LaTeX of the current module for debugging.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- (BlueprintGen.BlueprintContent.node n).toJson = Lean.Json.mkObj [("type", Lean.Json.str "node"), ("data", Lean.toJson n.toJson)]
- (BlueprintGen.BlueprintContent.modDoc d).toJson = Lean.Json.mkObj [("type", Lean.Json.str "moduleDoc"), ("data", Lean.toJson d.doc)]
Instances For
Equations
- BlueprintGen.moduleToJson module = do let __do_lift ← BlueprintGen.getBlueprintContents module pure (Lean.Json.arr (Array.map BlueprintGen.BlueprintContent.toJson __do_lift))
Instances For
Equations
- BlueprintGen.mainModuleToJson = do let __do_lift ← BlueprintGen.getMainModuleBlueprintContents pure (Lean.Json.arr (Array.map BlueprintGen.BlueprintContent.toJson __do_lift))
Instances For
Shows the blueprint JSON of the current module for debugging.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Write the result content
to the appropriate blueprint file with extension ext
("tex" or "json").
Equations
- One or more equations did not get rendered due to their size.
Instances For
Write latex
to the appropriate blueprint tex file.
Equations
- BlueprintGen.outputLatexResults basePath module latex = BlueprintGen.outputResultsWithExt basePath module latex "tex"
Instances For
Write json
to the appropriate blueprint json file.
Equations
- BlueprintGen.outputJsonResults basePath module json = BlueprintGen.outputResultsWithExt basePath module json.pretty "json"
Instances For
Write to an appropriate index tex file that \inputs all modules in a library.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Write to an appropriate index json file containing paths to json files of all modules in a library.
Equations
- One or more equations did not get rendered due to their size.