看看下面的 MWE。
\PassOptionsToPackage{export}{adjustbox}
\documentclass{article}
\usepackage{fancyvrb}
\usepackage{graphicx}
\usepackage{adjustbox}
\newcounter{psextern}
\makeatletter
\renewcommand\FVB@VerbatimOut[1]{%
\@bsphack%
\begingroup
\FV@UseKeyValues%
\FV@DefineWhiteSpace%
\def\FV@Space{\space}%
\FV@DefineTabOut%
\def\FV@ProcessLine##1{%
\toks@{##1}\immediate\write\FV@OutFile{\the\toks@}}%
\immediate\openout\FV@OutFile #1\relax%
\WritePreamble%<<=== write preamble
\let\FV@FontScanPrep\relax
\let\@noligs\relax%
\FV@Scan}
\renewcommand\FVE@VerbatimOut{%<<=== write postamble
\WriteLine{\string\end{document}}% <<
\immediate\closeout\FV@OutFile\endgroup\@esphack}
\newcommand\WriteLine[1]{%
\begingroup%
\let\protect\@unexpandable@protect%
\edef\reserved@a{\immediate\write\FV@OutFile{#1}}%
\reserved@a%
\endgroup}
\makeatother
\newcommand\WritePreamble{%
\WriteLine{\string\documentclass[multido=false,margin=3pt]{standalone}}%
% \WriteLine{\string\input{preamble/preamble-externalb}}%
\WriteLine{\string\usepackage[T1]{fontenc}}%
\WriteLine{\string\usepackage[utf8]{inputenc}}%
\WriteLine{\string\usepackage[osf]{mathpazo}}%
\WriteLine{\string\linespread{1.05}\selectfont}%
\WriteLine{\string\usepackage[scaled=.88]{beramono}}%
\WriteLine{\string\usepackage[scaled=.86]{berasans}}%
\WriteLine{\string\usepackage[dvipsnames,table,svgnames,xcdraw,showerrors]{xcolor}}%
\WriteLine{\string\usepackage{pstricks}}%
\WriteLine{\string\usepackage{pst-func}}%
\WriteLine{\string\usepackage{rotating}}%
\WriteLine{\string\usepackage{pst-blur}}%
\WriteLine{\string\usepackage{pst-lens}}% Seite 436
\WriteLine{\string\usepackage{pst-slpe}}%
\WriteLine{\string\usepackage{pst-circ}}%
\WriteLine{\string\usepackage{pst-3d}}%%27.07.2012 testweise
\WriteLine{\string\usepackage{pst-3dplot}}%%27.07.2012 testweise
\WriteLine{\string\usepackage{pst-plot}}%%27.07.2012 testweise
\WriteLine{\string\usepackage{pst-coil}}%% 1.7.2014
\WriteLine{\string\usepackage{pst-diffraction}}%%27.07.2012 testweise
\WriteLine{\string\usepackage{pst-vue3d}}%
\WriteLine{\string\usepackage{pst-bar}}%%27.07.2012 testweise
\WriteLine{\string\usepackage{pst-barcode}}%
\WriteLine{\string\usepackage{pst-all}}%
\WriteLine{\string\usepackage{pst-uml}}%
\WriteLine{\string\usepackage{pstricks-add}}%% muß als letztes Paket geladen werden. Erkenntnis vom 27.07.2012, PStricks, 6. Auflage, S.647 letzte Zeile.
\WriteLine{\string\usepackage{pst-fill}}%
\WriteLine{\string\usepackage{pst-light3d}}%
\WriteLine{\string\usepackage{pst-solides3d}}%%27.07.2012 testweise geht nicht
\WriteLine{\string\usepackage{eso-pic}}%
\WriteLine{\string\usepackage{fp}}%
\WriteLine{\string\usepackage{gradientframe}}%
\WriteLine{\string\usepackage[cleanup={log,aux,dvi,ps,pdf}]{auto-pst-pdf}}%
\WriteLine{\string\begin{document}}%
}
%%
\newcommand\Export[1]{%
\stepcounter{psextern}%
\gdef\psexternExt{#1}%
\VerbatimEnvironment%
\begin{VerbatimOut}{\jobname-#1\thepsextern.tex}}
%%
\def\endExport{%
\end{VerbatimOut}
\IfFileExists{\jobname-\psexternExt\thepsextern.tex}
{\typeout{>>>running pdflatex with file ./figures/pdf-export/\jobname-\psexternExt\thepsextern.tex}%
\immediate\write18{pdflatex --interaction=nonstopmode \jobname-\psexternExt\thepsextern}
\immediate\write18{call fcopy \jobname-\psexternExt\thepsextern}
}
{\fbox{Error in Export!}}%
\IfFileExists{./figures/pdf-export/\jobname-\psexternExt\thepsextern.pdf}
{\includegraphics{./figures/pdf-export/\jobname-\psexternExt\thepsextern}}
{\fbox{Error in running \jobname-\psexternExt\thepsextern.tex~ Try again}}%
}
% \usepackage[export]{adjustbox}
\begin{document}
\begin{figure}\centering
\adjustbox{scale=0.25}{
\begin{Export}{fig}
\DeclareFixedFont{\Rm}{T1}{ptm}{m}{n}{3cm}
\begin{pspicture}(-11,-11)(11,11)
\psset{linestyle=none,fillstyle=solid}%
\PstLightThreeDText[fillcolor=Violet, LightThreeDColorPsCommand=2.5 div 0.7 exch 0.8 sethsbcolor]{\Rm 987}\\[1cm]
\PstLightThreeDText[fillcolor=DarkGreen,LightThreeDColorPsCommand=2 div 0.5 exch 0.2 exch sethsbcolor]{\Rm 987}
\end{pspicture}
\end{Export}
}
\end{figure}
\begin{table}[!htb]
\centering
\caption{A caption of a tabular}
\begin{Export}{tab}
\begin{tabular}{ccc}\hline
f & b & b \\\hline
foo & bar & baz \\\hline
\end{tabular}
\end{Export}
\end{table}
\begin{Export}{tab}
\begin{tabular}{l}
\psTilt{60}{%
\begin{tabular}{|p{0.7cm}|p{0.7cm}|p{0.7cm}|p{0.7cm}|p{0.7cm}|}\hline
\psrotateleft{Beispiel Nummer\ } & \psrotateleft{Arbeitsstunden\ }& \psrotateleft{Sekretariat [E/F]\ }& \psrotateleft{Reinigung [E/F]\ }& \psrotateleft{Gewinn\ }
\end{tabular}}\\\hspace*{-2.55em}
\begin{tabular}{|p{0.7cm}|p{0.7cm}|p{0.7cm}|p{0.7cm}|p{0.7cm}|}\hline
1 & 6 & 1E & 1E & 600 \\\hline
2A & 7 & 1F & 1E & 700 \\\hline
2B & 7 & 1E & 1F & 730 \\\hline
3 & 8 & 1F & 1F & \cellcolor{green!25}830 \\\hline
4 & 6 & 1F & 1F & \cellcolor{red!25}530 \\\hline
\end{tabular}
\end{tabular}
\end{Export}
\end{document}
(1)我希望有更多可能性来提供参数以包含图形。(缩放,旋转,页码)
(2)取决于一个(附加)参数,我想使用不同的前导码。
(3)取决于一个(附加)参数,我想使用不同的执行。
(4)依赖于一个(附加)参数,我想使用不同的方法来包含。
(5)应可以耕作。
(6)最后一张表在使用 pdflatex 编译时不能按预期工作,但 latex-divps-ps2pdf 可以
想一想
\begin{Export}[fig-pstricks]{scale=0.5}{angle=90}{page=1}{MOREPARAMS}
\end{Export}
(使用 pstricks 前言,使用 \includegraphics[...]{}...= pstrickscompile
\begin{Export}[fig-tikz]{scale=0.5}{angle=90}{page=1}{MOREPARAMS}
\end{Export}
(使用 tikz 前言,使用 \includegraphics[...]{}...= tikzcompile
\begin{Export}[animate]{scale=0.5}{framerate=12}{filename}{first}{last}{label}{MOREPARAMS}
\end{Export}
(使用动画前言,使用 \animategraphics[][...]{}...=
应该可以扩展代码,因为结构很清晰。
答案1
您可以使用简单的\ifx
比较,其中仅使用参数的首字母:
\newcommand{\WritePreamble}[1]{%
\def\PreambleType{2}% predefined, mybe any other value
\ifx#1n \def\PreambleType{0}\else% n)one
\ifx#1s \def\PreambleType{1}\fi\fi% s)small
\ifnum\PreambleType=0
---
\fi
\ifnum\PreambleType=1
...
\fi
...
}
none
在这种情况下,使用或n
作为参数没有任何区别。
答案2
这是我自己解决问题的又一次尝试。但我仍然遇到一些麻烦。
[1] 我找不到将 \WritePreamble{none} 替换为 \WritePreamble{##2} 的解决方案
[2] 我尝试了一些带条件的解决方案,但都失败了... [3] 我无法确定如何将参数包含在 \endExport 中(因此 \endExport[9]
如果有人有任何想法,那将会非常有帮助......
\documentclass{scrreprt}
\usepackage[german]{babel}
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage[utf8]{inputenc} % Uses the utf8 input encoding
\usepackage[osf]{mathpazo} % Palatino as the main font
\linespread{1.05}\selectfont
\usepackage{graphicx}
\usepackage{etoolbox}
\usepackage{textcomp}
\usepackage{pstricks}
\usepackage{pst-plot}
% \usepackage{auto-pst-pdf}
\usepackage{preview}
\usepackage{fancyvrb}
\newenvironment{standaloneb}{\begin{preview}}{\end{preview}}
\PreviewEnvironment{tikzpicture}
\newcounter{extern}
\makeatletter
\renewcommand\FVB@VerbatimOut[2]{%
\@bsphack%
\begingroup
\FV@UseKeyValues%
\FV@DefineWhiteSpace%
\def\FV@Space{\space}%
\FV@DefineTabOut%
\def\FV@ProcessLine##1{%
\toks@{##1}\immediate\write\FV@OutFile{\the\toks@}}%
\immediate\openout\FV@OutFile #1\relax%
\WritePreamble{none}%<<=== write preamble (small should be a variable, \WritePreamble{##2} for example)
\let\FV@FontScanPrep\relax
\let\@noligs\relax%
\FV@Scan}
\renewcommand\FVE@VerbatimOut{%<<=== write postamble
\WriteLine{\string\end{document}}% <<
\immediate\closeout\FV@OutFile\endgroup\@esphack}
\newcommand\WriteLine[1]{%
\begingroup%
\let\protect\@unexpandable@protect%
\edef\reserved@a{\immediate\write\FV@OutFile{#1}}%
\reserved@a%
\endgroup}
\makeatother
\newcommand{\WritePreamble}[1]{%
% \ifnum\pdfstrcmp{#1}{none}=0% pseudocode...
\WriteLine{\string\PassOptionsToPackage{dvipsnames,table,svgnames,xcdraw,showerrors}{xcolor}}
\WriteLine{\string\documentclass[multido=false,margin=3pt]{standalone}}%
% \WriteLine{\string\usepackage[T1]{fontenc}}
\WriteLine{\string\usepackage[utf8]{inputenc}}
\WriteLine{\string\usepackage[osf]{mathpazo}}
\WriteLine{\string\linespread{1.05}\selectfont}
\WriteLine{\string\usepackage[scaled=.88]{beramono}}
\WriteLine{\string\usepackage{textcomp}}
\WriteLine{\string\usepackage{xcolor}}
\WriteLine{\string\usepackage{pstricks}}
\WriteLine{\string\usepackage{pstricks-add}}
\WriteLine{\string\usepackage{auto-pst-pdf}}
\WriteLine{\string\begin{document}}%
% \fi% pseudocode...
% \ifnum\pdfstrcmp{#1}{small}=0% pseudocode...
% the following line will be commented...
% \WriteLine{\string\PassOptionsToPackage{dvipsnames,table,svgnames,xcdraw,showerrors}{xcolor}}
% \WriteLine{\string\documentclass[border=0pt]{standalone}}
% \WriteLine{\string\usepackage{morewrites}}
% \WriteLine{\string\usepackage{ifpdf}}
% \WriteLine{\string\usepackage[T1]{fontenc}}
% \WriteLine{\string\usepackage[utf8]{inputenc}}
% \WriteLine{\string\usepackage[osf]{mathpazo}}
% \WriteLine{\string\linespread{1.05}\selectfont}
% \WriteLine{\string\usepackage[scaled=.88]{beramono}}
% \WriteLine{\string\usepackage[scaled=.86]{berasans}}
% \WriteLine{\string\usepackage{xcolor}}
% \WriteLine{\string\usepackage{expl3}}
% \WriteLine{\string\usepackage{xparse}}
% \WriteLine{\string\usepackage{eurosym}}
% \WriteLine{\string\usepackage{array}}
% \WriteLine{\string\usepackage{twoopt}}
% \WriteLine{\string\usepackage{forloop}}
% \WriteLine{\string\usepackage{datatool}}
% \WriteLine{\string\usepackage[gray]{databar}}
% \WriteLine{\string\usepackage{pstricks}}
% \WriteLine{\string\usepackage{pst-func}}
% \WriteLine{\string\usepackage{pst-blur}}
% \WriteLine{\string\usepackage{pst-lens}}
% \WriteLine{\string\usepackage{pst-slpe}}
% \WriteLine{\string\usepackage{pst-circ}}
% \WriteLine{\string\usepackage{pst-3d}}
% \WriteLine{\string\usepackage{pst-3dplot}}
% \WriteLine{\string\usepackage{pst-light3d}}
% \WriteLine{\string\usepackage{pst-plot}}
% \WriteLine{\string\usepackage{pst-coil}}
% \WriteLine{\string\usepackage{pst-diffraction}}
% \WriteLine{\string\usepackage{pst-vue3d}}
% \WriteLine{\string\usepackage{pst-bar}}
% \WriteLine{\string\usepackage{pst-barcode}}
% \WriteLine{\string\usepackage{pst-uml}}
% \WriteLine{\string\usepackage{pstricks-add}}
% \WriteLine{\string\usepackage{pst-fill}}
% \WriteLine{\string\usepackage{pst-solides3d}}
% \WriteLine{\string\usepackage{pst-tree}}
% \WriteLine{\string\usepackage{ifthen}}
% \WriteLine{\string\usepackage{xspace}}
% \WriteLine{\string\usepackage{fp}}
% \WriteLine{\string\usepackage{pifont}}
% \WriteLine{\string\usepackage[nointegrals]{wasysym}}
% \WriteLine{\string\usepackage{MnSymbol}}
% \WriteLine{\string\usepackage{listings}}
% \WriteLine{\string\usepackage{hyperref}}
% \WriteLine{\string\ifpdf}
% \WriteLine{\string\else}
% \WriteLine{\string\usepackage[autotitle=true,german,fullbookmarks=false,lofbr=true,evenboxes=true,openmessage=false]{hypdvips}}
% \WriteLine{\string\bmstyle{0}{}}
% \WriteLine{\string\fi}
% \WriteLine{\string\usepackage{uhrzeit}}
% \WriteLine{\string\usepackage{auto-pst-pdf}}
% \WriteLine{\string\begin{document}}%
% \fi%
}
\newcommand\Export[2]{%
\stepcounter{extern}%
\gdef\externExt{#1}%
\gdef\externPre{#2}%
\VerbatimEnvironment%
\begin{VerbatimOut}{\jobname-\externPre-#1\theextern.tex}{\externPre}}
% \def\endExport[1]{% (input of variable to deside different compilevariants...
\def\endExport{%
\end{VerbatimOut}
% \ifnum\pdfstrcmp{#1}{pstricks}=0% pseudocode...
\IfFileExists{\jobname-\externPre-\externExt\theextern.tex}
{\typeout{>>>running pdflatex with file \jobname-\externPre-\externExt\theextern.tex}%
\immediate\write18{pdflatex --interaction=nonstopmode \jobname-\externPre-\externExt\theextern}}
{\fbox{Error in Export!}}%
\IfFileExists{\jobname-\externPre-\externExt\theextern.pdf}
{\includegraphics{\jobname-\externPre-\externExt\theextern}}
{\fbox{Error in running \jobname-\externPre-\externExt\theextern.tex~ Try again}}%
% \fi
% \ifnum\pdfstrcmp{#1}{animate}=0% pseudocode...
% \fi
}
\begin{document}
\begin{figure}\centering
\begin{Export}{fig}{none}
\begin{pspicture}(-5,-5)(5,5)
\pscircle*[linecolor=cyan]{5}
% \psgrid[subgriddiv=0,gridcolor=lightgray,gridlabels=0pt]
\Huge\sffamily\bfseries
\rput(-4.5,4.5){A} \rput(4.5,4.5){B}
\rput(-4.5,-4.5){C}\rput(4.5,-4.5){D}
\rput(0,0){auto-pst-pdf}
\rmfamily
\rput(0,-3.8){PSTricks}
\rput(0,3.8){\LaTeX}
\end{pspicture}
\end{Export}
\end{figure}
\end{document}
问题和答案基于 Herbert Voss从 latex 文件生成包含表格和图形的单独 pdf 文件?