13

Is there the possibility to produce PSTricks graphics in LuaLaTeX?

I tried it, but i get

    ! Undefined control sequence.
    <recently read> \c@lor@to@ps 

    l.9 \psline(
        -5,2)(5,4)

With auto-pst-pdf I get a warning to use pdflatex.

So how can i use pstricks in LuaLaTeX?

Edit:@Marco Daniel

I asked where to pack packages for specified for lualatex, "normal packages", and pstricks packages: Maybe something like this:

    \RequirePackage{ifluatex}
    \documentclass{scrartcl}
    \usepackage{amsmath}

    \ifluatex
        \usepackage{fontspec}
        \defaultfontfeatures{Ligatures=TeX}
        \usepackage{lua-visual-debug}
    \else
         \usepackage{pstricks}
         \usepackage{pst-plot}
    \fi
         \usepackage{auto-pst-pdf}
    \begin{document}
    Here text...
    \end{document}

Niklas

Niklas
  • 131

1 Answers1

8

You can't use PSTricks directly with LuaTeX as even in DVI mode you can't get the 'correct' output. As detailed on the PSTricks website, the way around this is to do a conditional compilation using auto-pst-pdf to generate the required graphical elements using pdfTeX in DVI mode:

\RequirePackage{ifluatex}
\documentclass{article}

\ifluatex
  \usepackage{fontspec}
  \setmainfont{TeX Gyre Pagella}
\else
  \usepackage{tgpagella}
  \usepackage{pstricks}
\fi
  \usepackage{auto-pst-pdf}

\begin{document}

\paragraph{Hier ein pstricks-Bild}
\begin{pspicture}(5,3)
  \pspolygon[fillstyle=vlines](0,0)(5,3)(3,0)
\end{pspicture}

\end{document} 

To see how this works, note that when auto-pst-pdf runs the auxiliary compiles, it always uses pdfTeX (in DVI mode). Thus the \ifluatex conditional will be false and any LuaTeX-specific stuff will be skipped. To get as close as possible appearance-wise, there is therefore a need to use a 'similar' font in the standard run route. Also note that anything to do with PSTricks goes in the 'else' branch: that includes additional PSTricks packages and anything else that needs DVI mode.

Bernard
  • 271,350
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
  • I think this answer is partially obsolete. Because recently there are many issues on compiling PSTricks with GhostScript, (according to Herbert) Lua is the recommended tool to process PSTricks. – Display Name Jan 04 '22 at 07:09
  • luapstricks https://ctan.org/pkg/luapstricks is a replacement for GhostScript and will automatically be loaded if one uses lualatex. However, some examples from pst-char won't work. – user187802 Oct 20 '22 at 12:07