在LaTeX样式/类文件中,有没有办法检测正在使用哪个输出设备(或至少具有哪些功能)?原因是,我正在编写一个类文件,其中我想使用一些Postscript特定的包(例如pstricks
),如果Postscript可用,但如果我只是写
\RequirePackage{pstricks}
Run Code Online (Sandbox Code Playgroud)
当然,如果我正在编译文档,那么会发生不好的事情pdflatex
.理想情况下,我正在寻找可以使用的东西
\if@postscriptokay\RequirePackage{pstricks}\fi
Run Code Online (Sandbox Code Playgroud)
看起来这一定是可能的,因为我知道类似的包pgf
可以改变他们的行为以使用基于输出设备的适当图形命令,但我已经完成了一些Google搜索并检查了我的LaTeX书并且没有找到方法.
\usepackage{ifpdf}
\ifpdf
% nothing
\else
\RequirePackage{pstricks}
\fi
Run Code Online (Sandbox Code Playgroud)
你可以像这样检测pdfTeX(这是做什么的ifpdf.sty
):
\makeatletter
\ifx\pdfoutput\@undefined
no pdfTeX
\else\ifnum\pdfoutput<1
pdfTeX is outputting a .dvi file
\else
pdfTeX is outputting a .pdf file
\fi\fi
Run Code Online (Sandbox Code Playgroud)
graphicx.sty,hyperref.sty和pgf.sty内置了自己的自动检测机制.它们根据自动检测和包选项加载不同的驱动程序文件(如pdftex.def
和hpdftex.def
).如果在.tex文件中加载其中任何一个,请尝试获取它们加载的驱动程序的信息.相关的驱动程序文件是:
/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsys-*.def
/usr/share/texmf-texlive/tex/latex/hyperref/hpdftex.def
/usr/share/texmf-texlive/tex/latex/graphics/*.def
/usr/share/texmf-texlive/tex/latex/pdftex-def/pdftex.def
Run Code Online (Sandbox Code Playgroud)
驱动程序的名称pgf.sty
和graphicx.sty
存储在宏中\Gin@driver
.加载任何这些包后,您可以检查此宏.