Вопрос по компиляции рисунков pgfplot/tikz через latex+dvips+ps2pdf

Вопрос по компиляции рисунков pgfplot/tikz через latex+dvips+ps2pdf

У меня много проблем при компиляции рисунков pgfplots/tikz через цепочку latex+dvips+ps2pdf. Я могу успешно скомпилировать тот же набор рисунков pgfplots/tikz через pdflatex. Причина, по которой мне нужно компилировать через цепочку latex+dvips+ps2pdf, заключается в том, что некоторые математические символы не встроены в файл pdf, сгенерированный pdflatex.

У меня следующие вопросы.

  1. Как включить рисунки в формате PDF с помощью \includegraphics и компиляции через цепочку latex+dvips+ps2pdf?

Если для этого варианта существует решение, то я могу сначала скомпилировать цифры pgfplots/tikz в выходные цифры pdf. Затем я могу включить цифры pdf, используя \includegraphics и компилируя через цепочку latex+dvips+ps2pdf.

  1. Проблема ограничивающего прямоугольника при компиляции рисунков pgfplots/tikz через цепочку latex+dvips+ps2pdf.

MWE называется example.texследующим образом:

\documentclass{article}
\usepackage{filecontents}
\usepackage[dvips]{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepgfplotslibrary{external}
\tikzexternalize
\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"; dvips -o "\image".ps "\image".dvi}}
\tikzset{external/force remake}

\begin{filecontents}{data.dat}
CLFREQT 0.000000 0.500000 20 1.200000 5.883213
CLFREQT 5.883213 7.559856 20 1.000000 6.823011
CLFREQT 12.706224 14.382867 20 0.800000 7.633751
CLFREQT 20.339976 20.489868 20 1.000000 6.165892
CLFREQT 26.505868 26.655760 20 0.800000 7.780472
CLFREQT 34.286340 32.880138 20 0.600000 8.835256
CLFREQT 43.121595 38.181291 20 0.800000 9.379904
CLFREQT 52.501500 45.685215 20 1.000000 9.601305
CLFREQT 62.102805 55.286519 20 1.200000 9.431572
CLFREQT 71.534377 66.604406 20 1.000000 9.924455
CLFREQT 81.458832 76.528861 20 1.200000 9.469530
CLFREQT 90.928361 87.892297 20 1.000000 5.099208
CLFREQT 96.027570 92.991505 20 0.800000 8.763533
\end{filecontents}

\begin{filecontents}{Fig.tikz}
\tikzsetnextfilename{Fig}
\begin{tikzpicture}
    \begin{axis}[
        legend pos=north west,
        legend style={font=\small},
        xmode=linear,
        ymode=linear,
        axis x line*=bottom,
        axis y line*=left,
        tick label style={font=\small},
        grid=both,
        tick align=outside, 
        tickpos=left,
        xlabel=xlabel,
        ylabel=ylabel,
        xmin=0,xmax=100,
        ymin=0,ymax=100,
        width=0.45\textwidth,
        height=0.4\textwidth,
    ]
    \addplot+[mark=*,raw gnuplot,color=red] gnuplot {
        plot 'data.dat' using 2:3 w lp lw 3;
    };
    \addlegendentry{Legend};
    \end{axis}
\end{tikzpicture}
\end{filecontents}

\begin{document}

\begin{figure}[bth]
    \begin{tabular}{p{2.25in}}
        \scalebox{0.5}[0.5]{\includegraphics[]{Fig.tikz}}
    \end{tabular}
    \caption{\small This is the caption.}
\end{figure}

\end{document}

Я компилирую файл example.tex через

latex -interaction=nonstopmode -shell-escape example.tex; dvips -o example.ps example.dvi; ps2pdf example.ps

Ошибки вывода:

! LaTeX Error: Cannot determine size of graphic in Fig.tikz (no BoundingBox).

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.61 ...ox{0.5}[0.5]{\includegraphics[]{Fig.tikz}}

<Fig.tikz> [1] (./example.aux) )
(see the transcript file for additional information)
Output written on example.dvi (1 page, 5416 bytes).
Transcript written on example.log.
This is dvips(k) 5.994 Copyright 2014 Radical Eye Software (www.radicaleye.com)
' TeX output 2014.10.02:1933' -> example.ps
</usr/local/texlive/2014/texmf-dist/dvips/base/tex.pro>
</usr/local/texlive/2014/texmf-dist/dvips/base/texps.pro>
</usr/local/texlive/2014/texmf-dist/dvips/base/special.pro>
</usr/local/texlive/2014/texmf-dist/dvips/base/color.pro>. 
</usr/local/texlive/2014/texmf-dist/fonts/type1/public/amsfonts/cm/cmr9.pfb>
</usr/local/texlive/2014/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
[1<./Fig.tikz>] 
Error: /undefined in \tikzsetnextfilename
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1900   1   3   %oparray_pop   1899   1   3   %oparray_pop   1883   1   3   %oparray_pop   1771   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1168/1684(ro)(G)--   --dict:0/20(G)--   --dict:86/200(L)--   --dict:181/300(L)--   --dict:66/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
Current file position is 57618
GPL Ghostscript 9.10: Unrecoverable error, exit code 1

В чем причина ошибки «Ошибка LaTeX: Невозможно определить размер рисунка»?

  1. Я попытался скомпилировать с помощью другого MWE, как показано ниже, через latex+dvips+ps2pdf.

    \documentclass{sig-alternate-10pt}
    
    \usepackage{lua-visual-debug}
    \usepackage{tikzscale}
    \usepackage{tikz}
    \usetikzlibrary{arrows,backgrounds,calc,shapes,patterns}
    \usetikzlibrary{er}
    \usepackage{tikz-3dplot}
    
    \usepackage{pgfplots}
    \usetikzlibrary{pgfplots.groupplots}
    
    \usepackage{pgfplotstable}
    \usepackage{currfile}
    \usepackage{lmodern}
    \usepackage{filecontents}
    
    \usetikzlibrary{spy}
    
    %\usepgflibrary{shapes.geometric}
    
    \usetikzlibrary{external}
    \tikzexternalize[prefix=figure-build/]
    %\tikzset{external/mode=list and make}
    %\tikzset{external/check=diff}
    
    %\tikzset{external/force remake}
    
    \pgfplotsset{compat=1.11}
    
    \tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\string\def\string\myopts{\myopts}\texsource" && dvips -o "\image".ps "\image".dvi}}
    
    \usepackage{import}
    \usepackage[open-square,define-standard-theorems]{QED}
    \usepackage{listings}
    
    % available fonts (9/94) seem to be:
    % avantgarde bookman chancery lucida ncs palatino times
    \hyphenation{hy-phen-ation}
    
    % poor man's doublespacing (useful for less-than-exactly double spacing)
    % \renewcommand{\baselinestretch}{1.5}
    
    %\include{prooftree}
    \includeonly{}
    
    \begin{filecontents}{data.dat}
    CLFREQT 0.000000 0.500000 20 1.200000 5.883213
    CLFREQT 5.883213 7.559856 20 1.000000 6.823011
    CLFREQT 12.706224 14.382867 20 0.800000 7.633751
    CLFREQT 20.339976 20.489868 20 1.000000 6.165892
    CLFREQT 26.505868 26.655760 20 0.800000 7.780472
    CLFREQT 34.286340 32.880138 20 0.600000 8.835256
    CLFREQT 43.121595 38.181291 20 0.800000 9.379904
    CLFREQT 52.501500 45.685215 20 1.000000 9.601305
    CLFREQT 62.102805 55.286519 20 1.200000 9.431572
    CLFREQT 71.534377 66.604406 20 1.000000 9.924455
    CLFREQT 81.458832 76.528861 20 1.200000 9.469530
    CLFREQT 90.928361 87.892297 20 1.000000 5.099208
    CLFREQT 96.027570 92.991505 20 0.800000 8.763533
    \end{filecontents}
    
    \begin{filecontents}{Fig.tikz}
    \tikzsetnextfilename{Fig}
    \begin{tikzpicture}
        \begin{axis}[
            legend pos=north west,
            legend style={font=\small},
            xmode=linear,
            ymode=linear,
            axis x line*=bottom,
            axis y line*=left,
            tick label style={font=\small},
            grid=both,
            tick align=outside,
            tickpos=left,
            xlabel=xlabel,
            ylabel=ylabel,
            xmin=0,xmax=100,
            ymin=0,ymax=100,
            width=0.45\textwidth,
            height=0.4\textwidth,
        ]
        \addplot+[mark=*,raw gnuplot,color=red] gnuplot {
            plot 'data.dat' using 2:3 w lp lw 3;
        };
        \addlegendentry{Legend};
        \end{axis}
    \end{tikzpicture}
    \end{filecontents}
    
    \begin{document}
    
    %\include{exercises}
    %\baselineskip=0.22 in
    % \draftheader
    %\renewcommand{\theequation}{\Roman{section}.\Alph{equation}}
    \setcounter{Result}{0}
    
    %% this line is needed to work together with QED.sty
    \setcounter{equation}{0}
    
    \reversemarginpar
    
    \thispagestyle{empty}
    \setcounter{page}{1}
    
    \title{Dummy Title}
    
    %\date{}
    \maketitle
    
    \begin{figure}[bth]
        \begin{tabular}{p{2.25in}}
            \scalebox{0.5}[0.5]{\includegraphics[]{Fig.tikz}}
        \end{tabular}
        \caption{\small This is the caption.}
    \end{figure}
    
    \end{document}
    

Я действительно не вижу большой разницы между двумя MWE, показанными на рисунках 2 и 3. Почему MWE в 2 не может быть скомпилирован, а MWE в 3 может быть скомпилирован?

Даже после успешной компиляции, файл pdf, показанный как прикрепленный, выглядит странно. На рисунке много пустого пространства. Как избавиться от пустого пространства? введите описание изображения здесь

Связанный контент