6

The last compiler to invoke is

ps2pdf -dAutoRotatePages#/None frames.ps

for Windows or

ps2pdf -dAutoRotatePages=/None frames.ps

for non-Windows.

The code snippet I want to invoke is as follows.

\foreach \compiler/\ext in {latex/tex,dvips/dvi,ps2pdf -dAutoRotatePages#/None/ps}
    {\immediate\write18{\compiler\space frames.\ext}}

But if you need the complete code, see my last answer here.

Probably the iterator gets confused with /None because / is used for the delimiter. How to escape /None?

  • 1
    What about \foreach \compiler/\ext in {latex/tex,dvips/dvi,{ps2pdf -dAutoRotatePages\string#/None}/ps}? – Qrrbrbirlbel Oct 31 '13 at 14:30
  • 1
    @Qrrbrbirlbel I tried it, but it doesn't work, because the braces aren't stripped off; \@firstofone{ps2pdf -dAutoRotatePages/string#/None}/ps works, though. – egreg Oct 31 '13 at 14:32
6

You don't want to only escape /None, but also # that's illegal in that context:

\edef\hms{\string#/}% Hash Mark Slash
\foreach \compiler/\ext in {latex/tex,dvips/dvi,ps2pdf -dAutoRotatePages\hms None/ps}
    {\immediate\write18{\compiler\space frames.\ext}}

The variant you mentioned in chat is even better:

\edef\AutoRotateOff{-dAutoRotatePages\string#/None}
\foreach \compiler/\ext in {latex/tex,dvips/dvi,ps2pdf \AutoRotateOff/ps}
    {\immediate\write18{\compiler\space frames.\ext}}

Both exploit the fact that \write fully expands its argument.

Another variant:

\makeatletter
\foreach \compiler/\ext in {latex/tex,dvips/dvi,%
  \@firstofone{ps2pdf -dAutoRotatePages\string#/None}/ps}
    {\immediate\write18{\compiler\space frames.\ext}}
\makeatother
2

Based on @egreg's answer, the / can be removed from \hms but we need {...} for ps2pdf item as follows.

\edef\hms{\string#}

\foreach \compiler/\ext in {latex/tex,dvips/dvi,{ps2pdf -dAutoRotatePages\hms/None}/ps}{\immediate\write18{\compiler\space temporary.\ext}}

MWE

% this input file name is filename.tex
% compile it with pdflatex -shell-escape filename.tex

\documentclass[preview,border=12pt]{standalone}

\usepackage{filecontents}

\begin{filecontents*}{temporary.tex}
\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}(4,2)
    \rput{90}(2,1){Marienplatz}
\end{pspicture}
\end{document}
\end{filecontents*}


\usepackage{graphicx,pgffor}
\edef\hms{\string#}

\foreach \compiler/\ext in {latex/tex,dvips/dvi,{ps2pdf -dAutoRotatePages\hms/None}/ps}{\immediate\write18{\compiler\space temporary.\ext}}

\begin{document}
\includegraphics{temporary}
\end{document}

More about Windows

In my experience with Windows 7, both -dAutoRotatePages=/None and -dAutoRotatePages#/None work on Windows. Therefore, the simplest solution just needs {...} as follows.

% this input file name is filename.tex
% compile it with pdflatex -shell-escape filename.tex

\documentclass[preview,border=12pt]{standalone}

\usepackage{filecontents}

\begin{filecontents*}{temporary.tex}
\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}(4,2)
    \rput{90}(2,1){Marienplatz}
\end{pspicture}
\end{document}
\end{filecontents*}


\usepackage{graphicx,pgffor}

\foreach \compiler/\ext in {latex/tex,dvips/dvi,{ps2pdf -dAutoRotatePages=/None}/ps}{\immediate\write18{\compiler\space temporary.\ext}}

\begin{document}
\includegraphics{temporary}
\end{document}

Warning

Don't replace \string# with \# as \# will not work (I just tried it).

  • My experience with Windows is void. ;-) – egreg Nov 5 '13 at 16:49
1
+500

edit (2017): since xint 1.1 (2014/10/28) one needed here \usepackage{xinttools}, not \usepackage{xint}.

As \xintForpair does not use / it is possible to have a simpler syntax:

% this input file name is filename.tex
% compile it with pdflatex -shell-escape filename.tex

\documentclass[preview,border=12pt]{standalone}
\usepackage{filecontents}

\begin{filecontents*}{temporary.tex}
\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}(4,2)
    \rput{90}(2,1){Marienplatz}
\end{pspicture}
\end{document}
\end{filecontents*}


\usepackage{graphicx}
\usepackage{xinttools}

\xintForpair #1#2 in 
   {(latex,tex),(dvips,dvi),(ps2pdf -dAutoRotatePages\string#/None,ps)}
\do {\immediate\write18{#1 temporary.#2}}

\begin{document}
\includegraphics{temporary}
\end{document}

Latest version of xint transparently removes spaces in comma separated lists, so the above may have all the additional spaces you desire around commas and parentheses.

  • It seems to me it will save more keystrokes. – kiss my armpit Nov 6 '13 at 21:38
  • @Marienplatz I am wondering why don't you use a single \immediate\write18 with &&: latex temporary.tex && dvips temporary.dvi && ps2pdf etc..., is it something one can not do on windows? (assuming you are on windows). – user4686 Nov 6 '13 at 21:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.