diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/bxdvidriver |
Initial commit
Diffstat (limited to 'macros/latex/contrib/bxdvidriver')
-rw-r--r-- | macros/latex/contrib/bxdvidriver/LICENSE | 21 | ||||
-rw-r--r-- | macros/latex/contrib/bxdvidriver/README.md | 104 | ||||
-rw-r--r-- | macros/latex/contrib/bxdvidriver/bxdvidriver.sty | 281 |
3 files changed, 406 insertions, 0 deletions
diff --git a/macros/latex/contrib/bxdvidriver/LICENSE b/macros/latex/contrib/bxdvidriver/LICENSE new file mode 100644 index 0000000000..8ada757fbc --- /dev/null +++ b/macros/latex/contrib/bxdvidriver/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2017 Takayuki YATO (aka. "ZR") + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/macros/latex/contrib/bxdvidriver/README.md b/macros/latex/contrib/bxdvidriver/README.md new file mode 100644 index 0000000000..bf2fb1f417 --- /dev/null +++ b/macros/latex/contrib/bxdvidriver/README.md @@ -0,0 +1,104 @@ +BXdvidriver Package +=================== + +LaTeX: To specify a driver option effective only in DVI output + +This single-function package enables authors to specify a global +driver option (dvips, dvipdfmx, etc) which is applied only when the +engine outputs a DVI file. It is useful to create special document- +templates that can be compiled in both PDF-mode and DVI-mode. + +### System requirement + + * TeX format: LaTeX. + * TeX engine: Anything. + * Dependent packages: + - ifpdf, ifluatex, ifxetex, ifvtex + - pdftexcmds + +### Installation + + - `*.sty` → $TEXMF/tex/latex/BXdvidriver + +### License + +This package is distributed under the MIT License. + +The bxdvidriver Package +----------------------- + +### Package Loading + + \usepackage[<option>,...]{bxdvidriver} + +The available options are described hereafter. + +#### Driver options + +The following driver options are available: + + dvips,xdvi,dvipdf,dvipdfm,dvipdfmx,dvipsone + dviwindo,oztex,textures,pctexps,pctex32 + +Suppose the document begins with: + + \documentclass[a4paper]{article} + \usepackage[dvipdfmx]{bxdvidriver} + \usepackage{graphicx,color} + +If the document is compiled with pdflatex (or xelatex, lualatex), then +the package does nothing and the driver option `dvipdfmx` is simply +ignored. + +However, if the document is compiled with latex (or any other engine +that outputs DVI files), then the package adds the given driver option +`dvipdfmx` to the global option list, and makes the settings effectively +the same as the following: + + \documentclass[a4paper,dvipdfmx]{article} + \usepackage{graphicx,color} + +The driver option is globally in effect, and thus the packages graphicx +and color will choose the driver for dvipdfmx. + +*Note.* Some care must be taken when the document class itself has some +driver-dependent behavior. In that case, simply loading bxdvidriver +after `\documentclass` would leave its driver option unapplied to the +document class. Instead, you must load the bxdvidriver package *before* +`\documentclass` with `\RequirePackage` command. + + \RequirePackage[dvipdfmx]{bxdvidriver} + \documentclass[a4paper]{some-fancy-class} + \usepackage{graphicx,color} + +#### Other options + +This package is essentially single-function, but as side effect it also +checks some integrity on driver settings: + + * whether (at most) one driver option is given; + * whether the driver matches the (PDF-output) engine; + * whether (at most) one graphics driver is loaded. + +By default, an error is issued when any check fails. But the behavior +can be changed by options. + + * `check` (default): Check failure issues an error. + * `nocheck`: Check failure does not issue an error. + +### Usage + +This package offers no user commands or environments. All the settings +are done by package options. + +Revision History +---------------- + + * Version 0.2a ‹2017/02/13› + - Bug fix. + * Version 0.2 ‹2016/03/26› + - The first public version. + +-------------------- +Takayuki YATO (aka. "ZR") +https://github.com/zr-tex8r diff --git a/macros/latex/contrib/bxdvidriver/bxdvidriver.sty b/macros/latex/contrib/bxdvidriver/bxdvidriver.sty new file mode 100644 index 0000000000..612249d600 --- /dev/null +++ b/macros/latex/contrib/bxdvidriver/bxdvidriver.sty @@ -0,0 +1,281 @@ +% bxdvidriver.sty + +%% package declaration +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{bxdvidriver}[2017/02/13 v0.2a] + +%% preparation +\def\bxdd@pkgname{bxdvidriver} +\providecommand\bxDebug[1]{} + +%--------------------------------------- general + +%% \bxdd@dvi@driver@list +% List of dvi-driver names. +\@onlypreamble\bxdd@dvi@driver@list +\def\bxdd@dvi@driver@list{% + dvips,xdvi,dvipdf,dvipdfm,dvipdfmx,dvipsone,% + dviwindo,oztex,textures,pctexps,pctex32} +%% \bxdd@pdf@driver@list +% List of pdf-driver names. +\@onlypreamble\bxdd@pdf@driver@list +\def\bxdd@pdf@driver@list{% + pdftex,xetex,luatex,vtex} + +%% packages +\RequirePackage{ifpdf,ifxetex,ifluatex,ifvtex} +\RequirePackage{pdftexcmds} + +%% variables +\newif\ifbxdd@ok +\@onlypreamble\bxdd@driver +\let\bxdd@driver\relax % driver given to this package +\@onlypreamble\bxdd@pdf@driver +\let\bxdd@pdf@driver\relax % actual pdf-mode driver, or \relax + +%% \[bxdd@T/<driver>] +\@for\bxdd@x:=\bxdd@dvi@driver@list\do{% + \expandafter\let\csname bxdd@T/\bxdd@x\endcsname=d} +\@for\bxdd@x:=\bxdd@pdf@driver@list\do{% + \expandafter\let\csname bxdd@T/\bxdd@x\endcsname=p} + +%% \bxdd@detokenize\CS +\def\bxdd@detokenize#1{% + \expandafter\bxdd@detokenize@a\meaning#1\relax#1} +\def\bxdd@detokenize@a#1>#2\relax#3{% + \def#3{#2}} + +%% switch 'bxdd@in@preamble' +\newif\ifbxdd@in@preamble +\ifx\documentclass\@twoclasseserror + \bxdd@in@preambletrue +\fi + +%--------------------------------------- options + +%% 'check'/'nocheck' +\newif\ifbxdd@check \bxdd@checktrue +\DeclareOption{check}{% + \bxdd@checktrue} +\DeclareOption{nocheck}{% + \bxdd@checkfalse} +%% driver options +\DeclareOption*{% + \bxdd@pfxplus\CurrentOption \ifx\bxdd@tmpa\@empty + \let\bxdd@tmpa\CurrentOption + \else + \expandafter\let\csname bxdd@T/\bxdd@tmpa\endcsname=d% + \fi + \expandafter\let\expandafter\bxdd@tmpb + \csname bxdd@T/\bxdd@tmpa\endcsname + \ifx\bxdd@tmpb\relax % unknown name + \PackageError\bxdd@pkgname + {Unknown driver name '\bxdd@tmpa' found}% + {The invalid option is ignored.\MessageBreak\@ehc} + \else\ifx\bxdd@driver\relax % first + \let\bxdd@driver\bxdd@tmpa + \else\ifx\bxdd@driver\bxdd@tmpa % repeated + \PackageInfo\bxdd@pkgname + {Redundant driver option '\bxdd@tmpa',\MessageBreak + found}% + \else % second + \PackageError\bxdd@pkgname + {Multiple driver options are given\MessageBreak + ('\bxdd@driver' and '\bxdd@tmpa')}% + {The extra option '\bxdd@tmpa' is ignored.\MessageBreak\@ehc} + \fi\fi\fi} +\def\bxdd@pfxplus#1{% + \expandafter\bxdd@pfxplus@a#1\@gobble+\@nil} +\def\bxdd@pfxplus@a#1+#2\@nil{% + \edef\bxdd@tmpa{\ifx\@nil#1\@nil#2\else\fi}} +%% +\ProcessOptions* + +%% check consistency +\ifx\bxdd@driver\relax + \PackageInfo\bxdd@pkgname + {No driver option given,} +\else\expandafter\ifx\csname bxdd@T/\bxdd@driver\endcsname p% + \PackageWarning\bxdd@pkgname + {The driver '\bxdd@driver' is a pdf-mode driver and\MessageBreak + inappropriate for this package,} +\else\bxDebug{driver=\bxdd@driver} +\fi\fi + +%--------------------------------------- pdf-mode detection + +%% check 'pdfmode' and set \bxdd@pdf@driver +\bxdd@oktrue +\ifluatex + \let\bxdd@tmpa\m@ne + \pdf@isprimitive\outputmode\outputmode{\let\bxdd@tmpa\outputmode}{} + \pdf@isprimitive\pdfoutput\pdfoutput{\let\bxdd@tmpa\pdfoutput}{} + \ifnum\bxdd@tmpa>\z@ + \def\bxdd@pdf@driver{luatex}% + \else\ifnum\bxdd@tmpa<\z@ + \PackageError\bxdd@pkgname + {INTERNAL ERROR (1)} + {Package loading is aborted.\MessageBreak\@ehc} + \bxdd@okfalse + \fi\fi +\else\ifxetex + \def\bxdd@pdf@driver{xetex} +\else\ifvtex + \def\bxdd@pdf@driver{vtex} +\else\ifpdf + \def\bxdd@pdf@driver{pdftex} +\fi\fi\fi\fi +\ifbxdd@ok\else +\expandafter\endinput\fi\relax + +% clear \bxdd@driver if pdf-mode +\ifx\bxdd@pdf@driver\relax\else + \PackageInfo\bxdd@pkgname + {Driver option '\bxdd@driver' is ignored, because\MessageBreak + the engine is in pdf-mode,} + \let\bxdd@driver\relax +\fi + +%--------------------------------------- append to global + +%% variables +\let\bxdd@gopt\relax +\let\bxdd@godrv\relax +\let\bxdd@godrv@multiple=M% flag value + +%% \bxdd@scan@global@options +\@onlypreamble\bxdd@scan@global@options +\def\bxdd@scan@global@options{% + \begingroup + \@for\bxdd@gopt:=\@classoptionslist\do{% + \let\bxdd@tmpa\bxdd@gopt \bxdd@detokenize\bxdd@tmpa + \expandafter\ifx\csname bxdd@T/\bxdd@tmpa\endcsname\relax\else + \ifbxdd@in@preamble + \@expandtwoargs\@removeelement\bxdd@gopt + \@unusedoptionlist\@unusedoptionlist + \fi + \ifx\bxdd@godrv\bxdd@gopt % just redundant + \else\ifx\bxdd@godrv\relax % first + \let\bxdd@godrv\bxdd@gopt + \else\ifx\bxdd@godrv\bxdd@godrv@multiple % more + \PackageInfo\bxdd@pkgname + {Extra driver option in global option list\MessageBreak + ('\bxdd@gopt'),}% + \else % second + \PackageInfo\bxdd@pkgname + {Multiple driver options in global option list\MessageBreak + ('\bxdd@godrv' and '\bxdd@gopt'),}% + \let\bxdd@godrv\bxdd@godrv@multiple + \fi\fi\fi + \fi} + \global\let\@unusedoptionlist\@unusedoptionlist + \aftergroup\bxdd@okfalse + \ifx\bxdd@godrv\relax + \ifx\bxdd@driver\relax\else + \PackageInfo\bxdd@pkgname + {Driver option '\bxdd@driver' is appended to the\MessageBreak + global option list,} + \aftergroup\bxdd@oktrue + \fi + \else\ifx\bxdd@godrv\bxdd@driver + \PackageInfo\bxdd@pkgname + {Driver option '\bxdd@driver' is already contained\MessageBreak + in the global option list,} + \else\ifx\bxdd@godrv\bxdd@godrv@multiple + \ifbxdd@check + \PackageError\bxdd@pkgname + {Multiple driver options in global option list\MessageBreak + (see log for detail)}% + {\@ehd}% + \fi + \else\ifx\bxdd@driver\relax + % nothing to do + \else % inconsistent + \ifbxdd@check + \PackageError\bxdd@pkgname + {The driver specified is '\bxdd@driver',\MessageBreak + but the global list contains '\bxdd@godrv'}% + {\@ehd}% + \else + \PackageInfo\bxdd@pkgname + {Driver option '\bxdd@driver' is discarded,\MessageBreak + because the global option list contains another driver\MessageBreak + '\bxdd@godrv',} + \fi + \fi\fi\fi\fi + \endgroup} + +%% append the specified driver option +\ifbxdd@in@preamble + \bxdd@scan@global@options + \ifbxdd@ok + \edef\bxdd@tmpa{% + \noexpand\g@addto@macro\noexpand\@classoptionslist{% + ,\bxdd@driver}% + }\bxdd@tmpa + \fi +\else % 'before-preamble' + \let\bxdd@org@fileswith@pti@ns\@fileswith@pti@ns + \def\@fileswith@pti@ns#1{% + \ifx#1\@clsextension + \let\@fileswith@pti@ns\bxdd@org@fileswith@pti@ns + \let\bxdd@org@fileswith@pti@ns\@undefined + \g@addto@macro\@documentclasshook{% + \bxdd@scan@global@options}% + \ifx\bxdd@driver\relax + \def\bxdd@tmpa{\@fileswith@pti@ns#1}% + \else + \edef\bxdd@tmpa{\noexpand\bxdd@tmpb{\bxdd@driver}}% + \def\bxdd@tmpb##1[##2]{\@fileswith@pti@ns#1[{##2,##1}]}% + \fi + \else + \def\bxdd@tmpa{\bxdd@org@fileswith@pti@ns#1}% + \fi + \bxdd@tmpa} +\fi + +%--------------------------------------- check for graphics drivers + +%% \bxdd@scan@graphics@drivers +\@onlypreamble\bxdd@scan@graphics@drivers +\def\bxdd@scan@graphics@drivers{% + \begingroup + \edef\bxdd@tmpa{\bxdd@dvi@driver@list,\bxdd@pdf@driver@list}% + \@for\bxdd@gopt:=\bxdd@tmpa\do{% + \expandafter\ifx\csname ver@\bxdd@gopt.def\endcsname\relax\else + \ifx\bxdd@godrv\relax % first + \let\bxdd@godrv\bxdd@gopt + \else\ifx\bxdd@godrv\bxdd@godrv@multiple % more + \PackageInfo\bxdd@pkgname + {Extra graphics driver is loaded\MessageBreak + ('\bxdd@gopt'),}% + \else % second + \PackageInfo\bxdd@pkgname + {Multiple graphics driver is loaded\MessageBreak + ('\bxdd@godrv' and '\bxdd@gopt'),}% + \let\bxdd@godrv\bxdd@godrv@multiple + \fi\fi + \fi} + \ifx\bxdd@godrv\relax + \PackageInfo\bxdd@pkgname + {No graphics driver used,} + \else\ifx\bxdd@godrv\bxdd@godrv@multiple + \ifbxdd@check + \PackageError\bxdd@pkgname + {Multiple graphics drivers are loaded\MessageBreak + (see log for detail)}% + {\@ehd}% + \fi + \else + \PackageInfo\bxdd@pkgname + {Graphics driver is '\bxdd@godrv',} + \fi\fi + \endgroup} + +%% add hook +\AtBeginDocument{% + \bxdd@scan@graphics@drivers} + +%--------------------------------------- all done +\endinput +%% EOF |