2

I've been trying to get the pst-optexp package working with the thesis template I have, and it's been a nightmare.

I'm using MikTeX with pdflatex compilation, as as previously mentioned in How to use PSTricks in pdfLaTeX? I have set the -enable-write18 flag.

\input{head/settings_thesis_template.tex}

\begin{document}
\include{main/optical_exp}
\end{document}

and settings_thesis_template.tex looks like this:

\documentclass[a4paper,11pt,fleqn]{book}
\usepackage{etex}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french,german,english]{babel}
\usepackage{fourier} 
\usepackage{setspace} % increase interline spacing slightly
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{bm} 
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{mdwlist}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage{lipsum}
\usepackage{microtype}
\usepackage{url}
\usepackage[final]{pdfpages}
\usepackage{fancyhdr}
\usepackage{listings}
\usepackage{hyperref}
\usepackage{color}
\usepackage{tikz}
\usetikzlibrary[topaths]
\usetikzlibrary{positioning,calc,arrows}

\usepackage[explicit]{titlesec}

\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{auto-pst-pdf}
\usepackage{pst-optexp}
\usepackage{pstricks-add}
\usepackage{pst-pdf}

and the image contained in optical_exp.tex is this:

\begin{pspicture}(-1.5,-1.5)(1.5,1.5)
\pnode(-1,0){in}
\pnode(0,0){mir}
\pnode(1,0){out}
\pnode(-1,-1){low}
\pnode(-1,1){high}
\mirror(low)(mir)(high)
\drawbeam[linecolor=red,arrows=->](in){1}(in)
\end{pspicture}

In the end, I get 1) the thesis file pdf, and 2) a blank, automatically generated pdf that is supposed to contain the image in "optical_exp-tex".

Interestingly, XeTex is able to compile this MWE. However, when I try to compile my more-complicated thesis template with XeTeX I get a bunch of unicode errors like the following:

Unicode char \u8:èse not set up for use with LaTeX
Unicode char \u8:éle not set up for use with LaTeX.

My file encoding is indeed UTF-8 and I have included the packages related to this error as you can see in my "settings" file. (Thanks to the thread inputenc Error: Unicode char \u8: not set up for use with LaTeX). It's probably the french text I have in the document, though I don't understand why I get this error despite having the "work-around" packages.

So the question is: 1)why does pdflatex not work with my MWE, and 2) why does XeTex give me UTF-8 encoding errors?

Any insight into these problems would be very welcome!

  • the unicode errors are because you should not use inputenc with xetex it is natively utf8 (but then you should use fontspec rather than fontenc to use a matching Unicode font encoding. – David Carlisle Feb 17 '15 at 20:37
  • I would load auto-pst-pdf after pstricks. Perhaps also, you shouldn't load both pst-pdf and auto-pst-pdf? – Bernard Feb 17 '15 at 21:03
  • @DavidCarlisle thanks, I replaced inputenc & fontenc with fontspec and now it runs. Unfortunately the thesis formatting got messed up. pdflatex respects the formatting, but does not generate the image even with Bernard's suggestions. Quite weird. Compiling with pdflatex, I changed the order of pstricks-add and auto-pst-pdf but to no avail. I also removed pst-pdf which did not seem to change anything. – drasticbutfine Feb 18 '15 at 08:05
  • Does the log file say anything about the external compilation of the images? Do you e.g. have a Perl interpreter which is required for pdfcrop to run? – Christoph Feb 18 '15 at 08:48
  • There is this snippet: ("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\pdfpages\pdfpages.sty" Package: pdfpages 2013/08/25 v0.4v Insert pages of external PDF documents (AM). I'm also curious as to why the pdf image is not generated correctly. – drasticbutfine Feb 18 '15 at 09:13
  • That is only the short description of the pdfpages package when it is loaded. No, I mean does the log say anything about if it succeeded to generate the external image (in your MWE, with pdflatex)? When it fails you should find something like "Package auto-pst-pdf Warning: Could not create file ...-pics.pdf". Please run pdfcrop without any argument on the command line to see if it works... And note, that xelatex probably doesn't work with pst-optexp, see http://tex.stackexchange.com/a/219781/33933. I never tested pst-optexp to work with XeLaTeX. – Christoph Feb 18 '15 at 09:20
  • Sorry, yes there is such a line. Package auto-pst-pdf Warning: Creation of mwe-thesis-pics.pdf failed. Package auto-pst-pdf Warning: Could not create mwe-thesis-pics.pdf. Auxiliary files not deleted.

    pdfcrop first was "not found", so I installed ActivePerl (running windows). Now the pdfcrop gives Can't use an undefined value as an ARRAY reference error... I guess I need to set some variables or paths somewhere?

    – drasticbutfine Feb 18 '15 at 10:01
  • I did also get this error message: I had to add the path to the Ghostscript bin directory to the PATH environment variable. – Christoph Feb 18 '15 at 12:02
  • I did that, and I can generate the -pdf with the image but the -pics is still not generated, and the image not included in the final pdf. Same error as above. I resorted to compiling with latex ->dvips -> ps2pdf in command line, and that works for now. – drasticbutfine Feb 19 '15 at 09:32

1 Answers1

2

I read the documentation at PSTricks website on tug.org, and apparently using tikz and pstricks together is a common mistake. The author offers a workaround like this, for using pst-plot with tikz.

For my particular example, I had to add

\usepackage{auto-pst-pdf}
\ifpdf
  \usepackage{tikz}
\else
  \usepackage{pst-optexp}
\fi

right after the \documentclass in the preamble, and remove the other \usepackage{tikz}.