What is the TEX file format?
.tex is the source file format for the LaTeX and TeX typesetting systems. Files with the .tex extension are plain-text documents processed by a TeX engine - they contain a mix of regular text and backslash commands that control layout, formatting, and structure. .tex files commonly include mathematical expressions, symbols, and scientific notation, written using TeX's powerful math typesetting syntax.
The main application of .tex files is the preparation of academic papers, scientific and engineering books, theses, and journal articles - any document where precise typesetting of complex mathematical or technical content matters. TeX was originally created by Donald Knuth in 1978, and LaTeX (a macro layer built on top of TeX, introduced by Leslie Lamport in 1984) is today the most widely used variant. A core advantage of the format is that the same .tex source compiles to identical output on any operating system, using engines such as pdflatex, xelatex, or lualatex to produce a PDF (or historically a DVI file). The document structure follows a standard pattern: a preamble beginning with \documentclass{...} declares the document class and loads packages via \usepackage{...}, followed by the body enclosed in \begin{document} and \end{document}.
Security & safety
RISK: MEDIUMA .tex file is plain text and harmless to read, but it is also EXECUTABLE markup: TeX runs as a program during compilation and, if shell-escape (\write18) is enabled, can run external system commands. A malicious .tex from an untrusted source could in principle write or execute files when compiled. Modern distributions restrict shell-escape by default, which limits this. Treat .tex files from unknown sources like downloaded code - inspect them first and don't enable unrestricted shell-escape. Viewing the source in a text editor carries no risk.
Format details
in a nutshellPrograms that open TEX files
Technical details
deep spec| File nature | Plain-text source document - human-readable and editable in any text editor; no binary encoding |
| Character encoding | ASCII or UTF-8; LaTeX has defaulted to native UTF-8 input since the October 2018 kernel release |
| MIME type | text/x-tex (primary); also recognized as application/x-tex, application/x-latex, and text/plain |
| File signature | None - no magic bytes or binary header; LaTeX files conventionally open with \documentclass{...} and all commands are prefixed with a backslash |
| Document structure | Preamble (\documentclass, \usepackage, custom settings) followed by the body between \begin{document} and \end{document} |
| Command syntax | Every formatting instruction is a backslash command (e.g., \textbf{}, \section{}, \frac{}{}); arguments in braces, optional arguments in square brackets |
| Math typesetting | First-class math mode: inline ($...$) and display (\[...\] or equation environment) for equations, fractions, integrals, matrices, and Greek letters |
| Compilation engines | pdfTeX/pdfLaTeX (most common), XeTeX/XeLaTeX (Unicode + OpenType fonts), LuaTeX/LuaLaTeX (Lua scripting), original tex engine (DVI output) |
| Output format | Compiled to PDF (via pdflatex, xelatex, or lualatex) or DVI (via the latex engine); the .tex file itself is never the finished document |
| Side files generated | Each compilation run creates .aux (cross-references), .log (engine log), .toc (table of contents), .bbl (bibliography), and .out (hyperref bookmarks) |
| Package ecosystem | Extended via .sty package files; CTAN hosts over 6,000 packages covering fonts, graphics, tables, chemistry, music notation, and more |
| Document classes | Document type set by \documentclass{...}: built-in classes include article, book, report, letter, and beamer (slides); custom classes use .cls files |
| Multi-file support | Large documents split across multiple .tex files linked via \input{filename} (direct inline inclusion) or \include{filename} (chapter-level with separate .aux handling) |
| Bibliography integration | External .bib database files processed by BibTeX or Biber; citations inserted with \cite{key} and resolved automatically during compilation |
| Typical file size | 1 KB to a few hundred KB per source file; large projects split across many .tex files rather than stored as one large document |
| Cross-platform consistency | Produces byte-for-byte identical typeset output on Windows, macOS, and Linux from the same .tex source - a core design goal of TeX since 1978 |
| Released | TeX 1978 (Knuth); LaTeX 1984 (Lamport) |
| Latest version | LaTeX2e (1994, ongoing biannual releases); LaTeX3/expl3 in active use. TeX engine frozen at 3.141592653 |
| Open standard | Yes · royalty-free |
| Specification | www.latex-project.org |
TEX conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about TEX files.