help for mktex Version 2.1 | 30Jan2026

Title

mktex - Convert Microsoft Word (.docx) documents to LaTeX (.tex) format with complete document structure and table of contents

Syntax

mktex using filename.docx [, replace compile language(str)]

where filename is a Microsoft Word document with .docx extension.

options

replace Overwrite existing .tex file

compile Compile to PDF using XeLaTeX (includes table of contents)

language(str) Document language (e.g., "chinese", "english")

Description

mktex converts Microsoft Word (.docx) documents to complete LaTeX (.tex) documents with table of contents support.
The command creates a full LaTeX document structure including preamble, packages, and proper document formatting.
It is optimized for both Chinese and English documents, with automatic language detection and appropriate package selection.

The generated LaTeX document includes a table of contents that is properly linked in the PDF output.
For Chinese documents, the command automatically includes the ctex package and sets appropriate fonts.

When the compile option is specified, the command performs two compilations with XeLaTeX to ensure
proper table of contents generation and cross-references.

Options

r (replace) overwrites an existing .tex file. Without this option,
the command exits with an error if the output file exists. Users can specify either
replace or simply r.

c (compile) compiles the generated .tex file to PDF using XeLaTeX.
Two compilations are performed to ensure proper table of contents and cross-references.
Requires a working LaTeX installation (TeX Live, MiKTeX, or MacTeX).
Users can specify either compile or simply c.

l (language) specifies the document language. For Chinese documents,
use "chinese", "zh", or "cn". For English documents, use "english" or "en".
Default is "chinese". Users can specify either language(chinese) or l(chinese).

Requirements

1. Pandoc: Must be installed from https://pandoc.org/installing.html.

2. LaTeX Distribution (for PDF compilation): TeX Live, MiKTeX, or MacTeX with XeLaTeX.

Cross-Platform Compatibility

mktex is designed to work on multiple operating systems:

• Windows: Uses system PATH to locate pandoc. Ensure pandoc is in your system PATH.

• macOS: For best results on macOS, define the pandoc path in your Stata profile.do file:

glo pandoc /opt/homebrew/bin/pandoc (for Homebrew installation)

glo pandoc /usr/local/bin/pandoc (for MacPorts installation)

• Linux: Uses system PATH. Ensure pandoc is installed and accessible.

The program automatically detects the operating system and adjusts its behavior accordingly.

Examples

Basic conversion of a Chinese document (creates .tex with table of contents):

. mktex using "report.docx"

Convert and compile to PDF, overwriting existing files (single-letter options):

. mktex using "thesis.docx", r c

Convert a Chinese document with explicit language specification:

. mktex using "test.docx", compile l(chinese)

Convert an English document with minimal options:

. mktex using "paper.docx", c l(english)

Using all single-letter abbreviations:

. mktex using "document.docx", r c l(english)

Output Files

The command produces the following output files:

1. .tex file: A complete LaTeX document with proper document structure including:
- Appropriate document class (article with ctex for Chinese, article for English)
- Required packages (geometry, hyperref, booktabs, graphicx, amsmath, amssymb)
- Table of contents generation command
- Full document preamble and body structure
- Proper hyperlink configuration for PDF navigation

2. .pdf file (with compile option): A compiled PDF document with:
- Proper table of contents with clickable links
- Correct font rendering for the specified language
- Proper page layout and margins
- Hyperlinked cross-references

Technical Details

The conversion process consists of five steps:

1. File Validation: Checks that the input file is a .docx file and exists.

2. Pandoc Conversion: Uses pandoc to convert the .docx file to basic LaTeX format.
On macOS, the program checks for a global pandoc path defined in profile.do.

3. Complete Document Creation: Builds a full LaTeX document structure including:
- Document class selection based on language
- Package imports for formatting and hyperlinks
- Table of contents setup
- Integration of converted content

4. Content Integration: Copies the converted content into the document body
while preserving all formatting and structure.

5. PDF Compilation (with compile option): Compiles the LaTeX file
to PDF using XeLaTeX with two passes for proper table of contents.

Chinese Quotation Marks Processing

Important technical note regarding Chinese quotation marks in the generated LaTeX files:

• The current version (2.1) has a known limitation: Chinese double quotation marks and their surrounding text may be lost during the conversion process.

• Users need to manually edit the generated .tex file to restore any missing Chinese quotation marks and the corresponding text.

• To properly typeset Chinese left double quotation marks in LaTeX, use two consecutive backticks (``) in the .tex file.

• For Chinese right double quotation marks, use two consecutive apostrophes ('').

• Example correction in LaTeX source code:
Original missing text → He said ``This is a Chinese example.''

• Always verify the converted content against the original Word document, especially sections containing Chinese punctuation.

• This limitation is due to character encoding issues in the pandoc conversion pipeline and will be addressed in future versions.

Chinese Text Processing

For Chinese documents, the command automatically:

• Uses ctex package for full Chinese language support

• Sets appropriate Chinese fonts for proper character rendering

• Handles Chinese punctuation and special characters

• Ensures proper line breaking and paragraph formatting

Table of Contents

The generated LaTeX document includes a functional table of contents:

• Automatically generated from document headings

• Properly formatted with LaTeX's native TOC system

• Clickable in PDF output when compiled with hyperref package

• Updated automatically during compilation process

Acknowledgments

The authors gratefully acknowledge the guidance and support of Christopher F. Baum.
His valuable advice on cross-platform compatibility and macOS-specific implementations
significantly improved the program's functionality across different operating systems.
His contributions to the Stata community and willingness to share knowledge have been instrumental
in enhancing the robustness of this tool.

Authors

Wu Lianghai and Chen Liwen

Anhui University of Technology (AHUT), Ma'anshan, China

Email: agd2010@yeah.net, 2184844526@qq.com

Wu Hanyan

Nanjing University of Aeronautics and Astronautics (NUAA), Nanjing, China

Email: 2325476320@qq.com

Wu Xinzhuo

University of Bristol (UB), London, UK

Email: 2957833979@qq.com

Ma Defang

Capital Normal University (CNU), Beijing, China

Email: 6346@cnu.edu.cn

See Also

art2tex - Convert academic articles to LaTeX format

case2tex - Convert case studies to LaTeX format

maketex - Creates a TeXable file from the using file

Version History

2.1 (30Jan2026): Added cross-platform compatibility with macOS support;
users can define pandoc path in profile.do on macOS; added acknowledgment to Christopher F. Baum.

2.0 (28Jan2026): Added complete LaTeX document structure with table of contents;
all options now support single-letter abbreviations; updated documentation.

1.0 (28Jan2026): Initial release as mktex, basic Chinese character handling.

Type help mktex to display this help file again.