A best-effort converter for transforming Excel tables into LaTeX format, enabling seamless integration of tabular data into LaTeX documents.
While Excel is excellent for data management and calculations, LaTeX offers crucial advantages for academic and technical publishing:
LaTeX tables provide:
- Perfect font matching: Your table fonts exactly match your document's font family, size, and style
- Professional typesetting: Beautiful mathematical formulas, consistent spacing, and professional layout
- Native integration: Use
\cref{}for cross-references,\ac{}for acronyms, and all LaTeX commands - Publication quality: High-quality output suitable for journals, theses, and conferences
- Math mode support: Preserve
$\gamma=0$,$\pi_H(s)$, and other mathematical notation - Bold/italic formatting: Maintain cell formatting from Excel
- Multiline format: Each column on a new line for better readability in source code
- Column comments: Automatic header comments show which column data belongs to
- Smart escaping: Proper handling of
%,&,$, and other special characters
- Python 3.13+ with
piporuv - TeX Live or similar LaTeX distribution (for compiling the output)
Using uv (recommended):
uv syncOr using standard pip:
pip install .For development purposes, install as editable:
pip install -e .# Using uv
uv run excel2latex.py input.xlsx -o output.tex
# Using Python directly
python excel2latex.py input.xlsx -o output.tex
# Using installed command
texcel input.xlsx -o output.tex# Using uv
uv run latex2excel.py input.tex -o output.xlsx
# Using installed command
latex2excel input.tex -o output.xlsxuv run excel2latex.py --helpOptions:
-o, --output FILE Output .tex file path (default: output_table.tex)
-s, --sheet NAME Sheet name or index (default: 0)
--no-multiline Use compact single-line format (default is multiline)
--no-escape Don't escape special characters (preserve math notation)
--no-formatting Don't preserve bold formatting from Excel
-c, --caption TEXT Table caption
--label TEXT LaTeX label (e.g., tab:mytable)
--skip-rows N Skip N rows at beginning
--landscape Use landscape mode (default: True)
--no-landscape Use portrait mode
-w, --width TEXT First column width (default: 2cm)
-f, --font SIZE Font size (tiny, scriptsize, footnotesize, small, normalsize)
uv run latex2excel.py --helpOptions:
-o, --output FILE Output .xlsx file path (default: output.xlsx)
-s, --sheet NAME Sheet name (default: Sheet1)
--keep-empty Keep empty rows in output
--no-formatting Don't preserve bold formatting
-t, --table-index N Table index to extract (0-indexed, default: 0)
# Standard Excel to LaTeX conversion (multiline format with comments)
uv run excel2latex.py table.xlsx -o table.tex
# Convert with caption and label
uv run excel2latex.py table.xlsx -o table.tex -c "My Table" -l "tab:mytable"
# Compact single-line format
uv run excel2latex.py table.xlsx -o table.tex --no-multiline
# Preserve math notation without escaping
uv run excel2latex.py table.xlsx -o table.tex --no-escape
# Custom first column width and font size
uv run excel2latex.py table.xlsx -o table.tex -w "3cm" -f footnotesize
# Convert LaTeX back to Excel
uv run latex2excel.py table.tex -o table.xlsx
# Extract specific table from multi-table LaTeX file
uv run latex2excel.py tables.tex -o table.xlsx -t 1The converter handles the most common Excel/LaTeX table features needed for LaTeX workflows:
- Cell content: Text, numbers, dates, formulas
- Math notation:
$\gamma=0$,$\pi_H(s)$,$\Delta[k_p, k_i]$preserved - Bold formatting: Bold cells wrapped in
\textbf{} - Empty rows: Converted to
\midrulefor visual separation - Empty columns: Converted to
|separators in column specification - Special characters: Automatic escaping of
%,&,$,#,_, etc. - Column comments: Header names added as comments for readability
- Tabular/tabularx: Both standard and tabularx environments
- Bold formatting:
\textbf{}cells marked as bold in Excel - Math notation: Preserved as LaTeX text (not converted to Unicode)
- Comments stripped: LaTeX comments (
%) properly removed - Empty cells: Preserved as empty Excel cells
- Multiple tables: Extract specific tables by index
- Complex Excel formatting (colors, merged cells) not preserved
- Images and charts not supported
- Excel formulas converted to values only
- LaTeX commands beyond basic formatting are stripped
- Create your table in Excel with data and formatting
- Add math notation using LaTeX syntax (e.g.,
$\gamma=0$) - Run conversion:
texcel table.xlsx -o table.tex - Include in LaTeX:
\input{table.tex}or copy the content - Compile: Your table appears with perfect formatting
- Export LaTeX table from your document
- Run conversion:
latex2excel table.tex -o table.xlsx - Edit in Excel: Modify data, add rows, etc.
- Convert back:
texcel table.xlsx -o table_updated.tex - Replace in document: Update your LaTeX file
| Tietze | Kampmeier | McC/Law | |
|---|---|---|---|
| Learning Paradigm | Batch, model-based | Sequential, PPO | Meta-RL |
| Math Test | $\gamma=0$ |
$\pi_H(s)$ |
100% |
\begin{table}[p]
\centering
\begin{tabularx}{\linewidth}{@{}>{\raggedright\arraybackslash}p{2cm} *{3}{>{\centering\arraybackslash}X}@{}}
\toprule
& \textbf{Tietze} % Tietze
& \textbf{Kampmeier} % Kampmeier
& \textbf{McC/Law} % McC/Law
\\
\textbf{Learning Paradigm}
& Batch, model-based % Tietze
& Sequential, PPO % Kampmeier
& Meta-RL % McC/Law
\\
\textbf{Math Test}
& $\gamma=0$ % Tietze
& $\pi_H(s)$ % Kampmeier
& 100\% % McC/Law
\\
\bottomrule
\end{tabularx}
\end{table}excel2latex/
├── excel_to_latex.py # Excel to LaTeX conversion
├── latex_to_excel.py # LaTeX to Excel conversion
├── pyproject.toml # Project configuration
├── test_comprehensive.py # Comprehensive test suite
├── test_roundtrip.py # Round-trip tests
└── README.md # This file
Run the test suite with pytest:
uv run pytestAll 29 tests cover:
- Empty column handling
- LaTeX comment stripping
- Empty rows as midrule
- Math symbol preservation
- Percent sign escaping
- Bold formatting
- Round-trip conversion
Contributions are welcome! Feel free to submit issues or pull requests for:
- Support for additional Excel features (colors, merged cells)
- Better formatting preservation
- Performance improvements
- Additional output formats
This project is licensed under the MIT License - see the LICENSE file for details.
- The LaTeX community for excellent documentation and packages
- OpenPyXL for Excel file handling
- Pandas for data manipulation