Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.