latex_pdf_build

This script will typeset a given root document into a PDF.

The following parameter is required:

r

the root document file; relative to the source directory -s

The following parameters are optional:

f

delete the output directory before typesetting

n

turn caching off, i.e., the auxiliary files will not be kept

o

the output directory ($PWD/build if not given)

s

the source the directory ($PWD/src if not given)

v

show diagnostic messages during typesetting

The PDF is generated using the XeTeX typesetting engine.

The value of Create Date is either the value of the SOURCE_DATE_EPOCH environment variable or the current timestamp.

The following will give you the timestamp of the HEAD commit:

SOURCE_DATE_EPOCH="$(git log --max-count=1 --pretty=format:%ct)"

Usage

$ scripts/latex/latex_pdf_build.sh -r main.tex

$ scripts/latex/latex_pdf_build.sh -r main.tex -s scripts/latex/example/src -o /tmp/example
$ tree --noreport /tmp/example
/tmp/example
├── aux                                                                   (1)
│   ├── main.aux
│   ├── main.fdb_latexmk
│   ├── main.fls
│   ├── main.log
│   └── main.xdv
└── main.pdf                                                              (2)
$ exiftool -createdate /tmp/example/main.pdf
Create Date                     : 2025:05:05 16:39:14Z                    (3)
$ SOURCE_DATE_EPOCH=0 scripts/latex/latex_pdf_build.sh -r main.tex -s scripts/latex/example/src -o /tmp/example -f -n
$ tree --noreport /tmp/example
/tmp/example
└── main.pdf                                                              (4)
$ exiftool -createdate /tmp/example/main.pdf
Create Date                     : 1970:01:01 00:00:00Z                    (5)
1 these auxiliary files speed up subsequent PDF generations
2 the typeset PDF
3 Create Date has been set to current date
4 the output directory has been cleaned (-f) and no auxiliary files have been created (-n)
5 Create Date has been set to the value of SOURCE_DATE_EPOCH

Example

$ cd scripts/latex/example
$ ../latex_pdf_build.sh -r main.tex

build/main.pdf

Typeset PDF: main.pdf

Prerequisites

  • pdf_remove_metadata

    $ exiftool /tmp/example/main.pdf
    ExifTool Version Number         : 13.25
    File Name                       : main.pdf
    Directory                       : /tmp/example
    File Size                       : 92 kB
    File Modification Date/Time     : 2025:05:05 18:43:06+02:00
    File Access Date/Time           : 2025:05:05 18:48:07+02:00
    File Inode Change Date/Time     : 2025:05:05 18:43:06+02:00
    File Permissions                : -rw-r--r--
    File Type                       : PDF
    File Type Extension             : pdf
    MIME Type                       : application/pdf
    PDF Version                     : 1.5
    Linearized                      : No
    Page Count                      : 3
    Creator                         :  XeTeX output 2025.05.05:1642
    Producer                        : xdvipdfmx (20240407)
    $ scripts/pdf/pdf_remove_metadata.sh /tmp/example/main.pdf
    $ exiftool build/main.pdf
    ExifTool Version Number         : 13.25
    File Name                       : main.pdf
    Directory                       : /tmp/example
    File Size                       : 93 kB
    File Modification Date/Time     : 2025:05:05 18:55:37+02:00
    File Access Date/Time           : 2025:05:05 18:55:37+02:00
    File Inode Change Date/Time     : 2025:05:05 18:55:37+02:00
    File Permissions                : -rw-------
    File Type                       : PDF
    File Type Extension             : pdf
    MIME Type                       : application/pdf
    PDF Version                     : 1.5
    Linearized                      : Yes
    Page Count                      : 3