1

Look at the following 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) I want to have more possibilities to provide parameters to includegraphics. (scaling, rotatet, pagenumber)

(2) Dependend on one (additional) parameter, I want to use different preambles.

(3) Dependend on one (additional) parameter, I want to use different executions.

(4) Dependend on one (additional) parameter, I want to use a different method to include.

(5) Cropping should be possible.

(6) The last table does not work as expected compiling with pdflatex, but it does latex-divps-ps2pdf

Think about

\begin{Export}[fig-pstricks]{scale=0.5}{angle=90}{page=1}{MOREPARAMS}

\end{Export}

(using pstricks preamble, uses \includegraphics[...]{}...= pstrickscompile

\begin{Export}[fig-tikz]{scale=0.5}{angle=90}{page=1}{MOREPARAMS}

\end{Export}

(using tikz preamble, uses \includegraphics[...]{}...= tikzcompile

\begin{Export}[animate]{scale=0.5}{framerate=12}{filename}{first}{last}{label}{MOREPARAMS}

\end{Export}

(using animate preamble, uses \animategraphics[][...]{}...=

it should be possible to extend the code, because the structure is clear.

2 Answers2

1

You can use a simple \ifx comparism where only the first letter of a parameter is used:

\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
  ...
}

In this case it makes no difference if you use none or n as parameter.

0

This is one more try to solve the question on my own. But I still have some troubles.

[1] I am not able to find a solution for \WritePreamble{none} replacing to \WritePreamble{##2}
[2] I have tried some solution with conditionals but all failed... [3] I am not able to determine how to include arguments to \endExport (so \endExport[9]

If someone has any ideas it would be very helpful...

\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}

Question and answer are based on Herbert Voss Generating a separate pdf file of tables and figures from a latex file?