module

Pomtex::Seed::Scanner

Statically scans .tex sources for the packages, classes and fonts they pull in, following local \input / \include / \subfile chains and local .sty/.cls files.

Constants

BABEL = /\\usepackage\s*\[([^\]]*)\]\s*\{babel\}/
BABEL_FLAGS = {"activeacute", "activegrave", "base", "bidi", "config", "hyphenmap", "keepshorthandsactive", "layout", "math", "noconfigs", "nocase", "provide", "safe", "shorthands", "showlanguages", "silent", "strings", "headfoot"}
BARE_INPUT = /\\input\s+([A-Za-z0-9_\-.\/]+)/
BIB_RESOURCE = Regex.new(("\\\\addbibresource" + OPT) + "\\{([^}]*)\\}")
BIB_STYLE = /\\bibliographystyle\s*\{([^}]*)\}/
BIBLIOGRAPHY = /\\bibliography\s*\{([^}]*)\}/
CLASSES = Regex.new(("\\\\(?:documentclass|LoadClass|LoadClassWithOptions)" + OPT) + "\\{([^}]*)\\}")
FONT_SETTERS = Regex.new(("\\\\(?:setmainfont|setsansfont|setmonofont|setmathfont|fontspec|newfontfamily\\s*\\\\[A-Za-z@]+|newfontface\\s*\\\\[A-Za-z@]+)" + OPT) + "\\{([^}]*)\\}")
GRAPHIC_EXTENSIONS = {".pdf", ".png", ".jpg", ".jpeg", ".eps", ".jbig2", ".jb2"}
GRAPHICS = Regex.new(("\\\\includegraphics\\*?" + OPT) + "\\{([^}]*)\\}")
GRAPHICS_PATH = /\\graphicspath\s*\{((?:\s*\{[^}]*\})+)\s*\}/
IMPORTS = /\\(?:sub)?import\*?\s*\{([^}]*)\}\s*\{([^}]*)\}/
INPUTS = /\\(?:input|include|subfile)\s*\{([^}]*)\}/
LISTING_INPUT = Regex.new(("\\\\(?:lstinputlisting|verbatiminput|VerbatimInput)" + OPT) + "\\{([^}]*)\\}")
LUA_MARKERS = /\\directlua|\\begin\{luacode\*?\}|\\luaexec/
MAGIC_PROGRAM = /%\s*!\s*TEX\s+(?:TS-)?program\s*=\s*([A-Za-z]+)/i
MINTED_INPUT = Regex.new(("\\\\inputminted" + OPT) + "\\{[^}]*\\}\\s*\\{([^}]*)\\}")
OPT = "(?:\\s*\\[[^\\]]*\\])*\\s*"
OPTIONAL = /\\InputIfFileExists\s*\{([^}]*)\}/
PACKAGES = Regex.new(("\\\\(?:usepackage|RequirePackage|RequirePackageWithOptions)" + OPT) + "\\{([^}]*)\\}")
PGF_LIBS = /\\usepgflibrary\s*\{([^}]*)\}/
PGFPLOTS_LIBS = /\\usepgfplotslibrary\s*\{([^}]*)\}/
TCB_LIBS = /\\tcbuselibrary\s*\{([^}]*)\}/
TCB_PACKAGE = /\\(?:usepackage|RequirePackage)\s*\[([^\]]*)\]\s*\{tcolorbox\}/
TCB_STYLE = /\\tcb@add@library@style\s*\{([^}]*)\}\s*\{([^}]*)\}/
TCB_STYLE_NAMES = {"most", "many", "all"}

babel package options that are not language names. tcolorbox library styles; their expansion is read from tcolorbox.sty.

THEMES = Regex.new(("\\\\use(|color|font|inner|outer)theme" + OPT) + "\\{([^}]*)\\}")
TIKZ_LIBS = /\\usetikzlibrary\s*\{([^}]*)\}/

Instance methods

babel_languages(options : String) : Array(String)

Language names from babel's options: turkish, or main=turkish.

Source
brace_depths(code : String) : Array(Int32)

Brace nesting depth at every character (escaped braces do not count).

Source
resolve_assets(result : ScanResult, root : Path) : Nil

Resolves asset references the way LaTeX would: relative to the including file, then the project root, then every \graphicspath entry for graphics.

Source
scan(path : Path | String) : ScanResult
Source
scan_source(text : String, result : ScanResult = ScanResult.new, top_level_only : Bool = false, &local : String -> Path | Nil) : ScanResult

Scans TeX source text (comments are stripped first). Exposed for testing.

With top_level_only, commands nested inside {...} are ignored. Package code wraps conditional loads in braces (\gdef\x{\RequirePackage{...}}, \IfPackageLoadedTF{...}{...}), while unconditional ones sit at the top.

Source
strip_comments(text : String) : String

Removes % comments while keeping escaped \%.

Source

Nested types