BUCKYVERSE

Date: 2025-04-16

Status

Accepted

Context

Our document processing pipeline relies heavily on LaTeX for high-quality typesetting, especially for academic and technical documents containing complex elements like:

The standard pdfLaTeX engine has limitations with:

Additionally, our HTML output needs to display mathematical content correctly across browsers and devices without requiring LaTeX installation.

These challenges affect several critical areas in our platform:

  1. Document processing reliability
  2. Output quality and consistency
  3. Cross-platform support
  4. Mathematical content rendering

Decision

We will implement the following LaTeX-related requirements:

1. LuaLaTeX as Primary Engine

We will standardize on LuaLaTeX as our primary LaTeX engine for the following reasons:

Implementation:

defmodule Codexis.Builders.LatexBuilder do
  def default_engine, do: "lualatex"
  
  def build_pdf(manuscript_path, options \\ []) do
    engine = Keyword.get(options, :engine, default_engine())
    # Engine-specific implementation
  end
end

2. Fontspec Integration

We will implement Fontspec integration to provide:

Standard configuration:

\\usepackage{fontspec}
\\setmainfont{DejaVu Serif}
\\setsansfont{DejaVu Sans}
\\setmonofont{DejaVu Sans Mono}

The system will:

3. MathJax for HTML Output

We will use MathJax for rendering math in HTML outputs:

Implementation approach:

Example configuration:

window.MathJax = {
  tex: {
    inlineMath: [['$', '$'], ['\\(', '\\)']],
    displayMath: [['$$', '$$'], ['\\[', '\\]']],
    processEscapes: true,
    packages: ['base', 'ams', 'noerrors', 'noundefined']
  },
  options: {
    renderActions: {
      findScript: [10, function (doc) {
        for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
          const display = node.type.includes('mode=display');
          const math = new doc.options.MathItem(
            node.textContent,
            doc.inputJax[0],
            display
          );
          const text = document.createTextNode('');
          node.parentNode.replaceChild(text, node);
          math.start = {node: text, delim: '', n: 0};
          math.end = {node: text, delim: '', n: 0};
          doc.math.push(math);
        }
      }, '']
    }
  }
};

4. LaTeX Package Requirements

Our system will require and manage the following core LaTeX packages:

Consequences

Positive

Negative

Mitigations

References