LATEX
application/x-latex
Magic Bytes
Offset: 0
25 20 2D 2A 2D 6C 61 74 65 78 2D 2A 2D
LaTeX is a document preparation system based on the TeX typesetting program, originally created by Leslie Lamport and currently maintained by the LaTeX Project. It serves as the standard for academic publishing, scientific documentation, and technical typesetting involving complex mathematical notation. While the source files consist of plain text and are inherently safe to view, the compilation process can execute system commands, necessitating caution when processing files from untrusted sources.
Validation Code
How to validate .latex files in Python
Python
def is_latex(file_path: str) -> bool:
"""Check if file is a valid LATEX by magic bytes."""
signature = bytes([0x25, 0x20, 0x2D, 0x2A, 0x2D, 0x6C, 0x61, 0x74, 0x65, 0x78, 0x2D, 0x2A, 0x2D])
with open(file_path, "rb") as f:
return f.read(13) == signature
How to validate .latex files in Node.js
Node.js
function isLATEX(buffer: Buffer): boolean {
const signature = Buffer.from([0x25, 0x20, 0x2D, 0x2A, 0x2D, 0x6C, 0x61, 0x74, 0x65, 0x78, 0x2D, 0x2A, 0x2D]);
return buffer.subarray(0, 13).equals(signature);
}
Go
func IsLATEX(data []byte) bool {
signature := []byte{0x25, 0x20, 0x2D, 0x2A, 0x2D, 0x6C, 0x61, 0x74, 0x65, 0x78, 0x2D, 0x2A, 0x2D}
if len(data) < 13 {
return false
}
return bytes.Equal(data[:13], signature)
}
API Endpoint
GET
/api/v1/latex
curl https://filesignature.org/api/v1/latex