Skip to content

⚡ LaTeX Injection

Seamlessly blend Markdown simplicity with LaTeX power using direct LaTeX injection. Perfect for advanced users who need precise typesetting control while maintaining the convenience of Markdown authoring.

Overview

LaTeX injection allows you to insert raw LaTeX code directly into your Markdown manuscripts. This bridges the gap between Markdown's simplicity and LaTeX's typesetting precision, giving you the best of both worlds.

When to Use LaTeX Injection

  • Advanced mathematical notation requiring specific LaTeX packages
  • Custom formatting not available in standard Markdown
  • Specialized symbols from LaTeX packages like physics, amsmath, or siunitx
  • Precise layout control for complex document structures
  • Advanced typesetting using pre-loaded LaTeX packages

Syntax

{{tex: LaTeX code}} - Inline LaTeX

Insert LaTeX code that gets rendered directly in your document:

{{tex: \usepackage{physics}}}

The quantum state is represented as {{tex: $\braket{\psi|\phi}$}}.

For unit vectors: {{tex: $\hat{\mathbf{n}}$}} where {{tex: $|\hat{\mathbf{n}}| = 1$}}.

Key characteristics: - Direct injection: LaTeX code passes through unchanged - Flexible placement: Use anywhere in your document - Package support: Import additional LaTeX packages - No escaping needed: Raw LaTeX syntax preserved

Practical Examples

Pre-loaded Package Features

These packages are already included and ready to use:

# Physics Notation Examples

Quantum mechanics notation: {{tex: $\langle\psi|\hat{H}|\psi\rangle$}}

SI units: {{tex: \SI{273.15}{\kelvin}}} and {{tex: \SI{10}{\nano\second}}}

Chemical formulas: {{tex: \ce{H2O + NaCl -> Na+ + Cl- + H2O}}}

TikZ graphics work directly in LaTeX injection blocks.

Available pre-loaded packages: - amsmath, amsfonts, amssymb - Advanced mathematics - siunitx - SI units and scientific notation - mhchem - Chemical formulas and equations - tikz - Graphics and diagrams - xcolor - Colors and highlighting - Many others (see style class for complete list)

Advanced Mathematical Notation

Quantum Mechanics

{{tex: \usepackage{physics}}}

The time evolution operator: {{tex: $\hat{U}(t) = \exp\left(-\frac{i}{\hbar}\hat{H}t\right)$}}

Expectation value: {{tex: $\expval{\hat{A}} = \braket{\psi|\hat{A}|\psi}$}}

Partial derivative: {{tex: $\pdv{f}{x}$}}

Chemistry

{{tex: \usepackage{chemformula}}}

Chemical reaction: {{tex: \ch{2 H2 + O2 -> 2 H2O}}

Complex molecule: {{tex: \ch{C6H12O6}} (glucose)

Units and Measurements

{{tex: \usepackage{siunitx}}}

Temperature: {{tex: \SI{273.15}{\kelvin}}}

Speed of light: {{tex: \SI{2.998e8}{\meter\per\second}}}

Measurement with uncertainty: {{tex: \SI{9.81 +- 0.02}{\meter\per\second\squared}}}

Custom Macros and Commands

Define reusable LaTeX macros:

{{tex: \newcommand{\prob}[1]{\mathbb{P}\left(#1\right)}}}
{{tex: \newcommand{\expect}[1]{\mathbb{E}\left[#1\right]}}}
{{tex: \newcommand{\var}[1]{\text{Var}\left[#1\right]}}}

# Statistical Analysis

The probability of success: {{tex: $\prob{X = 1} = p$}}

Expected value: {{tex: $\expect{X} = np$}}

Variance: {{tex: $\var{X} = np(1-p)$}}

Complex Equations and Alignments

{{tex: \usepackage{amsmath}}}

Multi-line equation with alignment:

{{tex:
\begin{align}
\nabla \cdot \mathbf{E} &= \frac{\rho}{\epsilon_0} \\
\nabla \cdot \mathbf{B} &= 0 \\
\nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} \\
\nabla \times \mathbf{B} &= \mu_0\mathbf{J} + \mu_0\epsilon_0\frac{\partial \mathbf{E}}{\partial t}
\end{align}
}}

These are Maxwell's equations in differential form.

Diagrams and Graphics

{{tex: \usepackage{tikz}}}

Simple diagram:

{{tex:
\begin{tikzpicture}
\draw (0,0) circle (1cm);
\draw (-1,0) -- (1,0);
\draw (0,-1) -- (0,1);
\node at (0,1.3) {Unit Circle};
\end{tikzpicture}
}}

Integration with Python Execution

Combine LaTeX injection with Python code for dynamic LaTeX generation:

{{py:exec
import numpy as np

# Generate LaTeX code for a matrix
matrix_data = np.array([[1, 2], [3, 4]])

# Create LaTeX matrix syntax
def array_to_latex(arr):
    rows = []
    for row in arr:
        rows.append(' & '.join(map(str, row)))
    return f"\\begin{{pmatrix}}\n{' \\\\\\\\ '.join(rows)}\n\\end{{pmatrix}}"

matrix_latex = array_to_latex(matrix_data)
determinant = np.linalg.det(matrix_data)
}}

{{tex: \usepackage{amsmath}}}

Our transformation matrix is:

{{tex: $A = {{py:get matrix_latex}}$}}

With determinant {{tex: $\det(A) = {{py:get determinant:.0f}}$}}.

Advanced Use Cases

Custom Theorem Environments

{{tex: \usepackage{amsthm}}}
{{tex: \newtheorem{theorem}{Theorem}}}
{{tex: \newtheorem{lemma}{Lemma}}}
{{tex: \newtheorem{proof}{Proof}}}

{{tex: \begin{theorem}}}
Every finite group of prime order is cyclic.
{{tex: \end{theorem}}}

{{tex: \begin{proof}}}
Let $G$ be a group of prime order $p$, and let $g \in G$ with $g \neq e$...
{{tex: \end{proof}}}

Bibliography Customization

{{tex: \usepackage[style=nature,backend=biber]{biblatex}}}
{{tex: \addbibresource{references.bib}}}

Standard citation: [@smith2023]

Custom citation format: {{tex: \cite[see][p.~25]{smith2023}}}

Layout and Formatting Controls

{{tex: \usepackage{geometry}}}
{{tex: \geometry{margin=1in,columnsep=0.5in}}}

{{tex: \usepackage{setspace}}}
{{tex: \doublespacing}}

Custom section formatting:
{{tex: \section*{Unnumbered Section}}}

Best Practices

1. Package Management

Place all package imports at the beginning of your document:

{{tex: \usepackage{physics}}}
{{tex: \usepackage{siunitx}}}
{{tex: \usepackage{chemformula}}}
{{tex: \usepackage{tikz}}}

# Document content starts here...

2. Macro Definitions

Define reusable macros early for consistency:

{{tex: \newcommand{\vect}[1]{\mathbf{#1}}}}
{{tex: \newcommand{\unit}[1]{\hat{\mathbf{#1}}}}
{{tex: \newcommand{\abs}[1]{\left|#1\right|}}

Vector notation: {{tex: $\vect{v} = \abs{\vect{v}}\unit{v}$}}

3. Error Prevention

Test complex LaTeX code separately before injection:

% Test in a separate .tex file first
\documentclass{article}
\usepackage{physics}
\begin{document}
$\braket{\psi|\hat{H}|\psi}$
\end{document}

4. Documentation

Comment complex LaTeX injections:

<!-- Custom theorem environment for main results -->
{{tex: \newtheorem{mainresult}{Main Result}}}

<!-- Physics notation setup -->
{{tex: \usepackage{physics}}}

Combining with Standard Markdown

LaTeX injection works seamlessly with standard Markdown features:

{{tex: \usepackage{physics}}}

## Quantum Mechanics Results

Our **key finding** shows that the wavefunction {{tex: $\psi(x,t)$}} satisfies:

> The time-dependent Schrödinger equation:
> {{tex: $i\hbar\frac{\partial}{\partial t}\psi(x,t) = \hat{H}\psi(x,t)$}}

For the harmonic oscillator potential {{tex: $V(x) = \frac{1}{2}m\omega^2x^2$}},
the energy eigenvalues are {{tex: $E_n = \hbar\omega(n + \frac{1}{2})$}}.

See Figure @fig:wavefunction for visualization.

Common Patterns

Physics Research

{{tex: \usepackage{physics}}}
{{tex: \usepackage{siunitx}}}

Energy: {{tex: $E = \SI{13.6}{\electronvolt}$}}
Momentum: {{tex: $\vb{p} = m\vb{v}$}}
Angular momentum: {{tex: $\vb{L} = \vb{r} \times \vb{p}$}}

Mathematical Proofs

{{tex: \usepackage{amsmath,amsthm}}}
{{tex: \newtheorem{theorem}{Theorem}}}

{{tex: \begin{theorem}}}
Statement of theorem...
{{tex: \end{theorem}}}

**Proof.** Mathematical argument using {{tex: $\epsilon$-$\delta$}} definition...

Chemistry Papers

{{tex: \usepackage{chemformula,siunitx}}}

Reaction: {{tex: \ch{A + B -> C + D}}
Rate constant: {{tex: $k = \SI{2.3e-5}{\per\second}$}}

Troubleshooting

Common Errors

Package conflicts:

<!-- Avoid conflicting packages -->
{{tex: \usepackage{amsmath}}}  <!-- Standard math -->
<!-- Don't also load mathtools if amsmath conflicts -->

Escaping issues:

<!-- Use raw LaTeX syntax -->
{{tex: $\alpha + \beta$}}  <!-- ✅ Correct -->
{{tex: $\\alpha + \\beta$}}  <!-- ❌ Double escaping -->

Placement problems:

<!-- Package imports must come before usage -->
{{tex: \usepackage{physics}}}  <!-- ✅ First -->
{{tex: $\braket{\psi|\phi}$}}  <!-- ✅ After package -->

Debugging Tips

  1. Test LaTeX separately in a minimal document
  2. Check package compatibility with your LaTeX distribution
  3. Use incremental injection - add one command at a time
  4. Review compilation logs for detailed error messages

Migration from Pure LaTeX

If you're converting existing LaTeX documents:

Before (Pure LaTeX):

\documentclass{article}
\usepackage{physics,siunitx}
\begin{document}

The expectation value $\braket{\psi|\hat{H}|\psi}$ equals
\SI{2.5}{\electronvolt}.

\end{document}

After (Rxiv-Maker with LaTeX injection):

{{tex: \usepackage{physics}}}
{{tex: \usepackage{siunitx}}}

# Quantum Analysis

The expectation value {{tex: $\braket{\psi|\hat{H}|\psi}$}} equals
{{tex: \SI{2.5}{\electronvolt}$}}.

Summary

LaTeX injection in Rxiv-Maker provides:

  1. Full LaTeX power within Markdown documents
  2. Package support for specialized notation
  3. Custom macro definition for consistency
  4. Seamless integration with Python execution and standard Markdown

Perfect for researchers who need advanced typesetting while maintaining the simplicity of Markdown authoring.

Next Steps: - Python Execution → for dynamic content - VS Code Extension → for enhanced editing - Examples → for real-world applications