exam2tex -- Generate Standardized LaTeX Exam Templates

exam2tex generates a professional LaTeX exam template that can be
compiled directly to PDF. It creates a complete framework with proper
formatting, bilingual support, and customizable sections for efficient
exam creation. The program includes automatic LaTeX special character
escaping, one-click compilation options, and ensures proper question
numbering alignment across all sections.

Syntax

exam2tex [filename] [,
subject(string)
grade(string)
date(string)
duration(string)
totalpoints(string)
teacher(string)
language(string)
header(string)
questionstart(#)
sections(numlist)
replace
texengine(string)
compile]

Options

subject(string) Exam subject (e.g., "Mathematics", "物理学")

grade(string) Grade/Class information (e.g., "Grade 10", "高一(3)班")

date(string) Exam date (default: \today)

duration(string) Exam duration (default: "120 minutes")

totalpoints(string) Total points possible (default: "100")

teacher(string) Teacher/Instructor name

language(string) Language selection: en (English, default) or cn (Chinese)

header(string) Custom LaTeX code to insert in preamble

questionstart(#) Starting question number (default: 1)

sections(numlist) Number of questions per section. Example: sections(5 4 3)

replace Replace existing output file

texengine(string) LaTeX engine: pdflatex (default), xelatex, or lualatex

compile Automatically compile the generated .tex file to PDF (runs twice for correct references)

Description

exam2tex creates a complete, professionally formatted LaTeX exam
template that follows academic standards. Version 1.0.1 includes a critical
fix for question numbering alignment in English papers, ensuring all
question numbers are consistently left-aligned throughout the document.
The generated file includes:

Key Features

Professional Document Structure

- Complete LaTeX preamble with essential packages
- Proper page geometry and margin settings
- Customizable header/footer with exam information
- Automatic question numbering and sectioning
- Optimized headheight (14.5pt) to eliminate LaTeX warnings

Perfect Question Numbering Alignment

- All question numbers are consistently left-aligned using \noindent
- No indentation differences between first and subsequent questions
- Works identically for both English and Chinese documents
- Professional appearance meeting academic standards

Bilingual Support

- Full support for both English (language(en)) and Chinese (language(cn))
- Automatic loading of appropriate language packages
- Localized instructions and section headings
- Compatible with xelatex for Chinese documents

Flexible Exam Design

- Multiple sections with customizable question counts
- Adjustable starting question number
- Custom LaTeX code injection via header() option
- Support for various LaTeX engines

LaTeX Safety Features

- Automatic escaping of underscores and other special characters
- Prevents common LaTeX compilation errors
- Properly formatted placeholder underlines

One-Click Compilation

- New compile option for automatic PDF generation
- Runs LaTeX engine twice to resolve all references
- Displays compilation progress and results

Examples

Basic English Exam

. exam2tex midterm, subject("Calculus I") grade("University Year 1")

. exam2tex midterm, subject("Calculus I") grade("University Year 1")
date("2026-03-01") duration("3 hours") totalpoints("120")

English Exam with One-Click Compilation

. exam2tex midterm, subject("Calculus I") grade("University Year 1")
date("2026-03-01") duration("3 hours") /// totalpoints("120") compile

Chinese Language Exam (using XeLaTeX)

. exam2tex final, subject("现代汉语") grade("二年级")
language(cn) texengine(xelatex) sections(4 5 4) compile

Multi-Section Exam with Custom Header

. exam2tex physics_final, subject("Physics 101") grade("Freshman")
sections(5 3 4 2) questionstart(1) ///
header("\newcommand{\bonuspoints}{10}") replace compile

Exam with Custom Teacher Name

. exam2tex final_exam, subject("Economics") grade("Sophomore")
teacher("Prof. Smith") date("2026-05-15") compile

Testing Question Numbering Alignment

. exam2tex alignment_test, subject("Test") grade("Demo")
sections(3 4) compile

Note: All question numbers will be perfectly aligned at the left margin,
both in Section A (questions 1-3) and Section B (questions 4-7).

Compiling to PDF

After generating the .tex file, you can compile it to PDF using your preferred
LaTeX engine. The program displays the appropriate command:

. pdflatex midterm.tex (for English documents)

. xelatex chinese_exam.tex (for Chinese documents)

For documents with cross-references, you need to run the compilation command
twice to resolve all references properly. Use the compile option to
automatically handle this.

Technical Notes

Question Numbering Implementation

- Version 1.0.1 uses \noindent before each question number
- This ensures all numbers start at the left margin
- Fix applies to both sectioned and non-sectioned exams
- Maintains consistent appearance across English and Chinese documents

LaTeX Special Characters

- Underscores (_) in any user input are automatically escaped as {\_}
- This prevents the common "Missing $" error in LaTeX compilation
- Placeholder underlines are properly formatted using {\_\_\_\_}

Automatic Compilation

- The compile option runs the LaTeX engine twice
- First run: Generates initial PDF and auxiliary files
- Second run: Resolves cross-references and page numbers
- PDF is saved in the same directory as the .tex file

Warning Elimination

- Headheight is set to 14.5pt to eliminate fancyhdr warnings
- LastPage references are properly resolved with two compilations
- No LaTeX errors should appear during compilation

Requirements

A working LaTeX distribution must be installed on your system:

- Windows: MiKTeX (https://miktex.org) or TeX Live
- macOS: MacTeX (https://tug.org/mactex/)
- Linux: TeX Live (via package manager)

For Chinese documents, ensure your LaTeX distribution includes:

- ctex package (for xelatex compilation)
- Appropriate Chinese fonts

Authors

Wu Lianghai

School of Business, Anhui University of Technology (AHUT)

Ma'anshan, Anhui, China

agd2010@yeah.net

Hu Fangfang

Wanjiang University of Technology (WJUT)

Ma'anshan, Anhui, China

huff470@163.com

Chen Liwen

School of Business, Anhui University of Technology (AHUT)

Ma'anshan, Anhui, China

2184844526@qq.com

Yang Lu

Rugao City Finance Bureau, Jiangsu Province

Jiangsu, China

1026835594@qq.com

Wu Hanyan

School of Economics and Management

Nanjing University of Aeronautics and Astronautics (NUAA)

Nanjing, Jiangsu, China

2325476320@qq.com

References

LaTeX Project. (2026). LaTeX - A document preparation system.
https://www.latex-project.org/

CTAN. (2026). The ctex package.
https://ctan.org/pkg/ctex

StataCorp. (2025). Stata 18 User's Guide. College Station, TX: Stata Press.

Also See

Online: Overleaf - Online LaTeX Editor

Stata commands: file, filefilter, shell

Version

Version 1.0.1 - 20 February 2026

Update History

v1.0.1 (20Feb2026): Fixed question numbering alignment issue in English
papers. All question numbers now consistently left-aligned using \noindent.
This ensures professional appearance matching academic standards.

v1.0.0 (15Feb2026): Initial release with bilingual support,
automatic special character escaping, and one-click compilation