在 MacBook Pro 上使用 TexShop 或 pdflatex 运行的 PSTricks LaTex 代码

在 MacBook Pro 上使用 TexShop 或 pdflatex 运行的 PSTricks LaTex 代码

我正在寻找可以在 MacBook Pro 笔记本电脑上使用 pdflatex 或 TexShop 运行的 PSTricks 示例代码。例如,我从

https://tug.org/PSTricks/main.cgi?file=pst-plot/pst-plotDemo#intro

具体来说,代码 pst-plot8Demo.tex 绘制了两个正弦波,如下所示,

\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{pst-plot}

\begin{document}
\psset{xunit=0.06,yunit=3}

\begin{pspicture}(-20,-1.25)(200,1.25)
  \psaxes[Dx=45,Dy=0.5]{-}(0,0)(0,-1.25)(200,1.25)
  \psplot{0}{180}{x sin} 
  \psplot[linestyle=dashed]{0}{180}{x 2 mul sin}
  \psplot[linestyle=dotted]{0}{180}{x sin add x 3 mul sin 0.75 mul} 
  \rput(90,1.25){CH}
  \rput(170,-0.7){CH\textsubscript{2}}
  \rput(180,0.5){CH\textsubscript{3}}
  \rput{90}(-20,0){$\frac{I}{\gamma(\textsuperscript{1}H)/
\gamma(\textsuperscript{13}C)}$}
\end{pspicture}

\end{document}

使用 TexShop 或 pdflatex 会产生同样的错误,即(pdflatex 运行错误如下所示)

***************************************************************
[JohnComputer:] john% pdflatex pst-plotDemo8.tex

This is pdfTeX, Version 3.141592653-2.6-1.40.23 (TeX Live 2022/dev) (preloaded format=pdflatex)

 restricted \write18 enabled.

entering extended mode

(./pst-plotDemo8.tex

LaTeX2e <2021-11-15>

L3 programming layer <2021-11-22>

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrartcl.cls

Document Class: scrartcl 2021/11/13 v3.35 KOMA-Script document class (article)

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrkbase.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrbase.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrlfile.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrlfile-hook.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrlogo.sty)))

(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics/keyval.sty)))

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/tocbasic.sty)

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/scrsize11pt.clo)

(/usr/local/texlive/2021/texmf-dist/tex/latex/koma-script/typearea.sty))

(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsmath.sty

For additional information on amsmath, use the `?' option.

(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amstext.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsgen.sty))

(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsbsy.sty)

(/usr/local/texlive/2021/texmf-dist/tex/latex/amsmath/amsopn.sty))

(/usr/local/texlive/2021/texmf-dist/tex/latex/pst-plot/pst-plot.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/pstricks/pstricks.sty

(/usr/local/texlive/2021/texmf-dist/tex/generic/iftex/iftex.sty)

(/usr/local/texlive/2021/texmf-dist/tex/latex/xcolor/xcolor.sty

(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics-cfg/color.cfg)

(/usr/local/texlive/2021/texmf-dist/tex/latex/graphics-def/pdftex.def))

(/usr/local/texlive/2021/texmf-dist/tex/generic/xkeyval/pst-xkey.tex

(/usr/local/texlive/2021/texmf-dist/tex/latex/xkeyval/xkeyval.sty

(/usr/local/texlive/2021/texmf-dist/tex/generic/xkeyval/xkeyval.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/xkeyval/xkvutils.tex))))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pst-fp.tex

`pst-fp' v0.06, 2020/11/20 (hv))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfutil-common.te

x

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfutil-common-li

sts.tex))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgfkeysfiltered.c

ode.tex))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/utilities/pgffor.code.tex

Loading pgffor.code.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex

)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.

tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic

.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigo

nometric.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.rando

m.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.compa

rison.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.

code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round

.code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.

code.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.integ

erarithmetics.code.tex)))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex)

))

`PSTricks' v3.11  <2021/09/27> (tvz,hv)

--- We are running latex or xelatex ---

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks.con)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks-color.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks-arrows.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks-dots.tex)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pstricks.con))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks/pst-fp.tex

`pst-fp' v0.06, 2020/11/20 (hv)))

(/usr/local/texlive/2021/texmf-dist/tex/latex/xkeyval/pst-xkey.sty)

(/usr/local/texlive/2021/texmf-dist/tex/latex/multido/multido.sty

(/usr/local/texlive/2021/texmf-dist/tex/generic/multido/multido.tex

 v1.42, 2010/05/14 <tvz>))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-plot/pst-plot.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-tools/pst-tools.tex

`PST-tools' v0.12, 2021/09/23 (hv))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pstricks-add/pstricks-add.tex

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-node/pst-node.tex

 v1.42a, 2020/04/01)

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-arrow/pst-arrow.tex

`pst-arrow' v0.05, 2021/11/16 (dr,hv))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-3d/pst-3d.tex

`PST-3d' v1.11, 2010/02/14 (tvz))

(/usr/local/texlive/2021/texmf-dist/tex/generic/pst-math/pst-math.tex

`pst-math' v0.64 , (CJ,hv)) `pstricks-add' v3.91, 2021/09/25 (dr,hv))

 v1.93, 2021/09/23 (tvz,hv)))

(/usr/local/texlive/2021/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)

(./pst-plotDemo8.aux)

(/usr/local/texlive/2021/texmf-dist/tex/context/base/mkii/supp-pdf.mkii

[Loading MPS to PDF converter (version 2006.09.02).]

)

! Undefined control sequence.

\c@lor@to@ps ->\PSTricks 

                         _Not_Configured_For_This_Format

l.9   \psplot

             {0}{180}{x sin}

? 

我下载并尝试过的许多示例都产生了相同的错误消息。

通过大量谷歌搜索,我了解到 pstricks 的 pdf 输出似乎存在问题。但是,我无法解决该问题。经过几个小时的谷歌搜索/研究/尝试不同的方法后,我放弃了。

顺便说一句,值得一提的是,我的最终目标是使用 Inkscape 输出 tex 代码,以便包含在更大的 LaTex 文档中。Inkscape 是一个图形程序,输出 pstricks 代码。

提前感谢您的任何帮助。

答案1

运行以下命令lualatex

% !TEX program = lualatex
\documentclass{standalone}
\usepackage{amsmath}
\usepackage{pst-plot}

\begin{document}
\psset{xunit=0.06,yunit=3}

\begin{pspicture}(-30,-1.3)(210,1.4)
  \psaxes[Dx=45,Dy=0.5]{-}(0,0)(0,-1.25)(200,1.25)
  \psplot{0}{180}{x sin} 
  \psplot[linestyle=dashed]{0}{180}{x 2 mul sin}
  \psplot[linestyle=dotted]{0}{180}{x sin add x 3 mul sin 0.75 mul} 
  \rput(90,1.25){CH}
  \rput(170,-0.7){CH\textsubscript{2}}
  \rput(180,0.5){CH\textsubscript{3}}
  \rput{90}(-20,0){$\frac{I}{\gamma(\textsuperscript{1}H)/
\gamma(\textsuperscript{13}C)}$}
\end{pspicture}

\end{document}

在此处输入图片描述

答案2

auto-pst-pdf当使用该包并使用编译器标志进行编译时,该示例可与 pdflatex 一起工作shell-escape

在后台,该包在相关的 PSTricks 代码上调用 latex+dvips,但作为用户,您只需运行一次 pdflatex。

梅威瑟:

\documentclass{scrartcl}
\usepackage{auto-pst-pdf}
\usepackage{amsmath}
\usepackage{pst-plot}

\begin{document}
\psset{xunit=0.06,yunit=3}

\begin{pspicture}(-20,-1.25)(200,1.25)
  \psaxes[Dx=45,Dy=0.5]{-}(0,0)(0,-1.25)(200,1.25)
  \psplot{0}{180}{x sin} 
  \psplot[linestyle=dashed]{0}{180}{x 2 mul sin}
  \psplot[linestyle=dotted]{0}{180}{x sin add x 3 mul sin 0.75 mul} 
  \rput(90,1.25){CH}
  \rput(170,-0.7){CH\textsubscript{2}}
  \rput(180,0.5){CH\textsubscript{3}}
  \rput{90}(-20,0){$\frac{I}{\gamma(\textsuperscript{1}H)/
\gamma(\textsuperscript{13}C)}$}
\end{pspicture}

\end{document}

结果:

在此处输入图片描述

答案3

Pstricks 不能直接与 pdflatex 配合使用。您可以直接使用 latex->dvips->ps2pdf 或 xelatex,但是,如果您使用的是较新版本的 Ghostscript,则需要使用配置为与较新的 Ghostscript 配合使用的 ps2pdf 或 xelatex。如果您拥有最新版本的 TeXShop 4.68,则有针对 latex->dvips->ps2pdf 和 xelatex 的专用引擎,并且已正确配置。它们被称为 latexTR 和 xelatexTR,但默认情况下未激活。要激活它们,请将 latexTR.engine 和 xelatexTR.engine 从 ~/Library/TeXShop/Engines/Inactive/GhostscriptTransparencyEngines 文件夹复制到上三层,即 ~/Library/TeXShop/Engines,然后重新启动 TeXShop。使用它们时,请将使用 latexTR 引擎的行放在源文档的顶部,或 将使用 xelatexTR 引擎的行放在% !TEX program = latexTR源文档的顶部。% !TEX program = xelatexTR然后使用 Typeset->Typeset (Cmd-T) 菜单命令排版文档。

要快速打开 ~/Library/TeXShop 文件夹,您可以使用 TeXShop->Open ~/Library/TeXShop 菜单命令。

相关内容