输出图形代码错误

输出图形代码错误
\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{amsmath}
\usepackage{pst-plot,pst-node}
\psset{algebraic,plotpoints=100,labelsep=3pt}

\def\f[#1,#2]{2*2^(-2.5*(#1-#2)^2)}

\begin{document}
\begin{pspicture}[showgrid=false](-3,0)(3.5,3)
    \psaxes[axesstyle=frame,tickstyle=bottom,ticks=x,ticksize=0 4pt,xsubticks=5,xsubticksize=.5,labels=none](0,0)(-3,0)(3,3)
    \uput[d](-1,0){$\omega_{\text{nl}}$}
    \uput[d](1.5,0){$\omega_{\text{lin}}$}
    \uput[d](0,0){\tiny Frequency}
    \psline{<-}(0,2)(1,2)
    \psset{linecolor=gray}
    \psline[linestyle=dashed](0,0)(0,3) 
    \psplot[linecolor=red,linestyle=dashed]{-3}{1}{\f[x,-1]}
    \psplot[linecolor=red]{-.5}{3}{\f[x,1.5]}
    \pcline{<->}(*-1.5 {\f[x,-1]})(*-.5 {\f[x,-1]})\nbput{$\Gamma_{\text{nl}}$}
    \pcline{<->}(*1 {\f[x,1.5]})(*2 {\f[x,1.5]})\nbput{$\Gamma_{\text{lin}}$}
\end{pspicture}
\end{document}

我请人画了一张图,他按照我展示的代码画了一张图。我试着在我的 Latex 文件中运行这个,但是没有成功。我该怎么办?此外,你能给我一些提示,让我可以用 LaTeX 代码画图吗?

enter image description here

编辑:

enter image description here

答案1

重要笔记

以下完整代码包装了主机输入文件(名为)中的latex-dvips-ps2pdf编译,并且必须使用diagram.texmain.texmain.tex

pdflatex -shell-escape main.tex

而不是

latex main.tex
dvips main.dvi
ps2pdf -dAutoRotatePages=/None main.ps

请仔细阅读我上面的注释!

完整代码

% the name of this file is main.tex
% compile it with
% pdflatex -shell-escape main.tex

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{diagram.tex}
\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{amsmath}
\usepackage{pst-plot,pst-node}
\psset{algebraic,plotpoints=100,labelsep=3pt}

\def\f[#1,#2]{2*2^(-2.5*(#1-#2)^2)}

\begin{document}
\begin{pspicture}[showgrid=false](-3,0)(3.5,3)
    \psaxes[axesstyle=frame,tickstyle=bottom,ticks=x,ticksize=0 4pt,xsubticks=5,xsubticksize=.5,labels=none](0,0)(-3,0)(3,3)
    \uput[d](-1,0){$\omega_{\text{nl}}$}
    \uput[d](1.5,0){$\omega_{\text{lin}}$}
    \uput[d](0,0){\tiny Frequency}
    \psline{<-}(0,2)(1,2)
    \psset{linecolor=gray}
    \psline[linestyle=dashed](0,0)(0,3) 
    \psplot[linecolor=red,linestyle=dashed]{-3}{1}{\f[x,-1]}
    \psplot[linecolor=red]{-.5}{3}{\f[x,1.5]}
    \pcline{<->}(*-1.5 {\f[x,-1]})(*-.5 {\f[x,-1]})\nbput{$\Gamma_{\text{nl}}$}
    \pcline{<->}(*1 {\f[x,1.5]})(*2 {\f[x,1.5]})\nbput{$\Gamma_{\text{lin}}$}
\end{pspicture}
\end{document}
\end{filecontents*}

\immediate\write18{latex diagram && dvips diagram && ps2pdf -dAutoRotatePages=/None diagram.ps}

\usepackage{graphicx}
\begin{document}

\begin{figure}[hbtp]
\centering
\caption{Spectrum}\label{fig:diagram}
\includegraphics{diagram}
\end{figure}
Beauty without intelligence is a masterpiece painted on a toilet paper.
\end{document}

更详细的解释

作为main.tex主机输入文件,有

\immediate\write18{latex diagram && dvips diagram && ps2pdf -dAutoRotatePages=/None diagram.ps}

它将会diagram.tex即时编译latex-dvips-ps2pdf

diagram.tex通过如下环境即时准备filecontents

\usepackage{filecontents}
\begin{filecontents*}{diagram.tex}
\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{amsmath}
\usepackage{pst-plot,pst-node}
\psset{algebraic,plotpoints=100,labelsep=3pt}

\def\f[#1,#2]{2*2^(-2.5*(#1-#2)^2)}

\begin{document}
\begin{pspicture}[showgrid=false](-3,0)(3.5,3)
    \psaxes[axesstyle=frame,tickstyle=bottom,ticks=x,ticksize=0 4pt,xsubticks=5,xsubticksize=.5,labels=none](0,0)(-3,0)(3,3)
    \uput[d](-1,0){$\omega_{\text{nl}}$}
    \uput[d](1.5,0){$\omega_{\text{lin}}$}
    \uput[d](0,0){\tiny Frequency}
    \psline{<-}(0,2)(1,2)
    \psset{linecolor=gray}
    \psline[linestyle=dashed](0,0)(0,3) 
    \psplot[linecolor=red,linestyle=dashed]{-3}{1}{\f[x,-1]}
    \psplot[linecolor=red]{-.5}{3}{\f[x,1.5]}
    \pcline{<->}(*-1.5 {\f[x,-1]})(*-.5 {\f[x,-1]})\nbput{$\Gamma_{\text{nl}}$}
    \pcline{<->}(*1 {\f[x,1.5]})(*2 {\f[x,1.5]})\nbput{$\Gamma_{\text{lin}}$}
\end{pspicture}
\end{document}
\end{filecontents*}

最后一步就是diagram.pdf按照宿主体内的图示来消耗。

\usepackage{graphicx}
\begin{document}

\begin{figure}[hbtp]
\centering
\caption{Spectrum}\label{fig:diagram}
\includegraphics{diagram}
\end{figure}
Beauty without intelligence is a masterpiece painted on a toilet paper.
\end{document}

如果您仍然不明白,请随意发表评论!

答案2

运行latex->ps产生以下.ps文件:

enter image description here

运行latex->ps->pdf会产生相同的输出,但pdf格式不同。例如,在 TeXnicCenter 中,您可以找到如下图所示的这些选项:

enter image description here

在WinEdt下,选项如下:

  1. 如图所示使用 LaTeX 进行编译。

    enter image description here

  2. 运行 dvi->ps。点击图标,enter image description here然后

  3. 如果需要 pdf,请点击enter image description here

或者在编译后点击enter image description here

相关内容