Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created July 12, 2014 15:14
Show Gist options
  • Select an option

  • Save zr-tex8r/08cdd6a868f06c641f25 to your computer and use it in GitHub Desktop.

Select an option

Save zr-tex8r/08cdd6a868f06c641f25 to your computer and use it in GitHub Desktop.
LaTeX: to use PSTricks with dvipdfmx
% bxdpx-pstricks.sty
\ifx\documentclass\undefined\long\def\nxt#1#2\nxt{#1}\nxt\fi
%[LaTeX code]
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bxdpx-pstricks}[2014/07/12 v0.2]
\def\bxqtd@pkgname{bxdpx-pstricks}
% package options
\DeclareOption{dvipdfmx}{\let\bxqtd@t=1}
\ProcessOptions*
\ifx\bxqtd@t\@undefined \expandafter\endinput\fi\relax
% environment check
\@ifclassloaded{pstricks}{%
\PackageError\bxqtd@pkgname{PSTricks is already loaded}%
{Package loading is aborted.}%
\endinput}{}
\IfFileExists{xdvipdfmx.cfg}{}{%else
\PackageError\bxqtd@pkgname{xetex-pstricks package is missing}%
{Package loading is aborted.}%
\endinput}
% write pctricks config
\chardef\bxqtd@t=15
\immediate\openout\bxqtd@t=pstricks.con\relax
\immediate\write\bxqtd@t{\noexpand\@@input xdvipdfmx.cfg\relax}
\immediate\closeout\bxqtd@t
% force to use PS color specials
% load all packages that read dvipdfmx.def
\@ifpackageloaded{graphics}{}{\RequirePackage[dvipdfmx]{graphics}}
\@ifpackageloaded{xcolor}{}{\RequirePackage[dvipdfmx]{xcolor}}
% and redefine color driver macros
\def\color@gray#1#2{\c@lor@arg{#2}\edef#1{gray #2}}
\def\c@lor@@cmyk#1,#2,#3,#4\@@#5{\c@lor@arg{#4}\c@lor@arg{#1}%
\c@lor@arg{#2}\c@lor@arg{#3}\edef#5{cmyk #1 #2 #3 #4}}
\def\c@lor@@rgb#1,#2,#3\@@#4{\c@lor@arg{#1}\c@lor@arg{#2}%
\c@lor@arg{#3}\edef#4{rgb #1 #2 #3}}
\def\c@lor@@hsb#1,#2,#3\@@#4{\c@lor@arg{#1}\c@lor@arg{#2}%
\c@lor@arg{#3}\edef#4{hsb #1 #2 #3}}
\def\current@color{gray 0}
\def\set@color{\special{color push \current@color}%
\aftergroup\reset@color}
\def\reset@color{\special{color pop}}
\def\set@page@color{\special{background \current@color}}
\def\define@color@named#1#2{%
\expandafter\edef\csname col@#1\endcsname{#2}}
% done
\endinput\noexpand\nxt
%[plain TeX code]
\chardef\nxt=15
\immediate\openout\nxt=pstricks.con\relax
\immediate\write\nxt{\noexpand\input xdvipdfmx.cfg\relax}
\immediate\closeout\nxt
% done
\endinput
%% EOF
\documentclass{article}
\usepackage[dvipdfmx]{bxdpx-pstricks}% Don't forget dvipdfmx option!
\usepackage{pstricks-add}
\begin{document}
\begin{center}
The graph of $y=0.4x^{4}-2x^{2}+2x$.\par
\psset{unit=0.6}
\psset{algebraic=true, VarStep=true,VarStepEpsilon=0.001}
\begin{pspicture*}(-4,-6)(4,6)
\psaxes[linewidth=1.2pt,labels=none,ticks=none]{->}(0,0)(-4,-6)(4,6)
\psplot[linecolor=red]{-4}{4}{0.4*x^4-2*x^2+x}
\uput[240](4,0){$x$}\uput[210](0,6){$y$}\uput[135](0,0){$\mathrm{O}$}
\end{pspicture*}
\end{center}
\end{document}
@PTW19
Copy link

PTW19 commented Mar 25, 2021

I'm using MiKTeX under Windows 10. Existing files using pstricks have stopped working, no doubt because I reinstalled MiKTeX a few days ago.

As an ab initio test, I just created exactly the above two files bxdpx-pstricks.sty and test.tex, and when I latex the latter followed by dvipdfmx I get what is evidently a wrong result, namely an equation in text with underneath a confused little squiggle that looks like a whole lot of symbols superimposed.

What has broken, and how can I fix it?

@PTW19
Copy link

PTW19 commented Mar 25, 2021

p.s. This is what dvipdfmx reports:

`dvipdfmx: security risk: running with elevated privileges
test.dvi -> test.pdf
[1Error: /undefined in TeXDict
Operand stack:

Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 2015 1 3 %oparray_pop 2014 1 3 %oparray_pop 1998 1 3 %oparray_pop 1884 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- 2015 1 3 %oparray_pop 2014 1 3 %oparray_pop 1998 1 3 %oparray_pop 1884 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:989/1684(ro)(G)-- --dict:0/20(G)-- --dict:165/200(L)--
Current allocation mode is local
Current file position is 715
MiKTeX GPL Ghostscript 9.25: Unrecoverable error, exit code 1

dvipdfmx:warning: Filtering file via command -->mgs.exe -q -dNOPAUSE -dBATCH -dEPSCrop -sPAPERSIZE=a0 -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dAutoRotatePages=/None -sOutputFile="C:/Users/Patrick/AppData/Local/Temp/mikA7B4.tmp" "C:/Users/Patrick/AppData/Local/Temp/mikA7A3.tmp" -c quit<-- failed.
dvipdfmx:warning: Image format conversion for PSTricks failed.
dvipdfmx:warning: Interpreting special command PST: (ps:) failed.
dvipdfmx:warning: >> at page="1" position="(237.592, 450.206)" (in PDF)
dvipdfmx:warning: >> xxx "PST: tx@Dict begin CM STV CP T newpath /a 0.0 def /w 136.57446"
Error: /undefined in TeXDict
Operand stack:

Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 2015 1 3 %oparray_pop 2014 1 3 %oparray_pop 1998 1 3 %oparray_pop 1884 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- 2015 1 3 %oparray_pop 2014 1 3 %oparray_pop 1998 1 3 %oparray_pop 1884 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:989/1684(ro)(G)-- --dict:0/20(G)-- --dict:165/200(L)--
Current allocation mode is local
Current file position is 715
MiKTeX GPL Ghostscript 9.25: Unrecoverable error, exit code 1
dvipdfmx:warning: Filtering file via command -->mgs.exe -q -dNOPAUSE -dBATCH -dEPSCrop -sPAPERSIZE=a0 -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dAutoRotatePages=/None -sOutputFile="C:/Users/Patrick/AppData/Local/Temp/mikA8FE.tmp" "C:/Users/Patrick/AppData/Local/Temp/mikA8BE.tmp" -c quit<-- failed.
dvipdfmx:warning: Image format conversion for PSTricks failed.
dvipdfmx:warning: Interpreting special command pst: (ps:) failed.
dvipdfmx:warning: >> at page="1" position="(305.624, 552.254)" (in PDF)
dvipdfmx:warning: >> xxx "pst: tx@Dict begin STP newpath /ArrowA { moveto } def /ArrowB "
Error: /undefined in TeXDict
Operand stack:

Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 2015 1 3 %oparray_pop 2014 1 3 %oparray_pop 1998 1 3 %oparray_pop 1884 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- 2015 1 3 %oparray_pop 2014 1 3 %oparray_pop 1998 1 3 %oparray_pop 1884 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:989/1684(ro)(G)-- --dict:0/20(G)-- --dict:165/200(L)--
Current allocation mode is local
Current file position is 715
MiKTeX GPL Ghostscript 9.25: Unrecoverable error, exit code 1
dvipdfmx:warning: Filtering file via command -->mgs.exe -q -dNOPAUSE -dBATCH -dEPSCrop -sPAPERSIZE=a0 -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dAutoRotatePages=/None -sOutputFile="C:/Users/Patrick/AppData/Local/Temp/mikAA09.tmp" "C:/Users/Patrick/AppData/Local/Temp/mikA9F9.tmp" -c quit<-- failed.
dvipdfmx:warning: Image format conversion for PSTricks failed.
dvipdfmx:warning: Interpreting special command pst: (ps:) failed.
dvipdfmx:warning: >> at page="1" position="(305.624, 552.254)" (in PDF)
dvipdfmx:warning: >> xxx "pst: tx@Dict begin STP newpath /ArrowA { moveto } def /ArrowB "
]
6692 bytes written`

@PTW19
Copy link

PTW19 commented Mar 29, 2021

After a great deal of very helpful investigation by Herbert Voss, it has emerged that the symptoms are suppressed if the reference to dvipdfmx is removed. Thus commenting out

\usepackage[dvipdfmx]{bxdpx-pstricks}% Don't forget dvipdfmx option!

corrects the problem. But note that:

  1. If there is a file pstricks.con this must be deleted first.
  2. The sequence of commands that I used is latex, dvips, ps2pdf.

I have no idea why dvipdfmx is causing a problem, and as my fix involves simply managing without it, I'd class the above as a workaround rather than a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment