Output LaTeX code that loads a package (possibly with an option) if it hasn't been loaded yet. LaTeX cannot load twice a package with different options, so this helper can be used to protect against users loading arbitrary packages/options in their custom preamble.
(package, *, option=None)
| 36 | |
| 37 | |
| 38 | def _usepackage_if_not_loaded(package, *, option=None): |
| 39 | """ |
| 40 | Output LaTeX code that loads a package (possibly with an option) if it |
| 41 | hasn't been loaded yet. |
| 42 | |
| 43 | LaTeX cannot load twice a package with different options, so this helper |
| 44 | can be used to protect against users loading arbitrary packages/options in |
| 45 | their custom preamble. |
| 46 | """ |
| 47 | option = f"[{option}]" if option is not None else "" |
| 48 | return ( |
| 49 | r"\makeatletter" |
| 50 | r"\@ifpackageloaded{%(package)s}{}{\usepackage%(option)s{%(package)s}}" |
| 51 | r"\makeatother" |
| 52 | ) % {"package": package, "option": option} |
| 53 | |
| 54 | |
| 55 | class TexManager: |
no outgoing calls
no test coverage detected
searching dependent graphs…