# pstricks not working with thesis template

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{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. – Deniz Feb 18 '15 at 8: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 8: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. – Deniz Feb 18 '15 at 9:13

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.

\usepackage{auto-pst-pdf}

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