## #340 inline preview with XeLaTeX (was: fontspec not compatible...

open
nobody
None
5
2012-10-17
2012-10-11
Luis
No

I've installed MiKTeX 2.9 and TeXStudio 2.4. I found suggestions on the web to change the default compiler to XeLaTeX, to provide accentuated words (I am portuguese!), to handle any type of images (pdf, eps, jpg, etc) and also to use system fonts. This seemed very interesting, as I usually use pdfLaTeX. However, when I use the fontspec package, the Inline preview of TeXStudio does not work (it gives errors). Is there any known bug or incompatibility of fontspec with inline preview?

## Discussion

• Tim Hoffmann
2012-10-12

• Luis
2012-10-13

So, the example is as follows

\documentclass{article}

\usepackage{fontspec}

\begin{document}
Olá, eu sou o Luís.
\begin{document}
Olá, eu sou o Luís.

$x^2+2x+1$
\end{document}

I run the file with XeLatex and the results is as expected. However, if I select the formula $x^2+2x+1$ and use the inline preview (Alt+P), it gives me errors and does not show the result:
"Process started: latex.exe -src -interaction=nonstopmode "ZM1708".tex
Process exited with error(s)
Process started: dvipng.exe -T tight -D 120 "ZM1708".dvi
Process exited with error(s)"

If I put %\usepackage{fontspec}, then I have no accents in the words (Olá appears simply as Ol and Luís as Lus), but now I get the possibility to perform the inline preview.

So the problem seems to be with the fontspec package...

Any help?

• Tim Hoffmann
2012-10-13

The preview compilation is based on latex (Actually latex->dvipng or latex->dvips->gostscript). To guarantee correct output it generates a temporary document using the header (everything before begin document) and the formular.

The problem with fontspec is that it does not work with latex, but requires xelatex or lualatex. Therefore it generates the error.

• Luis
2012-10-13

Ok, I understand that. But is there any solution or workaround for this? Xelatex should be kind of an evolution for older Tex engines. Can I use another package to ensure accents (inputenc does not work with Xelatex). Can I get system fonts in another way?

Is there anything like "If engine=Xelatex then fontspec, else %fontespec "

thank you

• Tim Hoffmann
2012-10-14

I'm not an expert in encodings, so I cannot comment if there is another way.

The most general solution from the TXS side would be to support XeLaTeX and/or LuaLaTeX for preview generation. The key issue here is to extract a cropped image from the PDF, which can then be used for the preview. I don't know right know how to do this - maybe ghostscript can do this?

Moved to feature request.

• Tim Hoffmann
2012-10-14

As a workaround, you can use the following code
\usepackage{ifxetex}
\ifxetex
\usepackage{fontspec}
\else
\fi

This will not include fontspec for the latex run in preview. Of course, if you add accented characters in your formula, they will not be displayed in the inline preview. But at least You can generate inline previews.

• Luis
2012-10-14

That's perfect! In fact, the inline previews are useful for big mathematical formulas, so the accented words are not needed.