Circuitikz - Partway 修饰符在 Emacs 预览模式下的行为有所不同

Circuitikz - Partway 修饰符在 Emacs 预览模式下的行为有所不同

我的源代码的这个简化版本在通过 LaTeX 运行和使用 Emacs/Auctex 预览模式查看时会产生不同的结果。 我的问题是如何通过预览解决这个问题。

\documentclass{article}

\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{circuitikz}
\usetikzlibrary{calc}
\newcommand{\marknode}[2][45]{%
  \node[circle, draw, red, inner sep=1pt, pin={[red,
    font=\tiny]#1:#2}] at (#2.center) {}; }

\begin{document}
\begin{figure}[h]
  % \renewcommand{\marknode}{}
  \centering
  \begin{circuitikz}
    \def\dx{3} \def\dy{4} \draw (0,0) node[ground,name=gnd] {} (gnd)
    ++(0,\dy) coordinate(a) to[american voltage source,
    l_=$\begin{matrix} & + \\ & V_\textsc{s} \\ & \qty{10}{V} \\ & -
    \end{matrix}$,name=Vs] (gnd)
    (Vslabel) ++(-0.5,0) node[] {$I_\textsc{s} \big\uparrow$}
    ;
    \marknode{a} \marknode{Vslabel}
    \path (a) ++(\dx,0) coordinate(b);
    \marknode{b}
    \path ($(a)!0.5!(b)$) coordinate(c);
    \marknode{c}
  \end{circuitikz} \caption{Test circuit}
  \label{fig:test-circuit}
\end{figure}
\end{document}

当通过 LaTeX 运行时,它看起来正如我所想的那样:

在此处输入图片描述

但是当使用预览查看时,它看起来像这样:

在此处输入图片描述

我尝试将第 22 行中的 partway 修饰符括在括号 {} 中。LaTeX 输出没有变化,但运行 preview-at-point (Cc Cp C_p) 会在 Emacs minimbuffer 中产生此错误:

在此处输入图片描述

以及大量的 Ghostscript 错误(416 行,我不愿意在这里给读者带来这些错误,但如果这有助于解决我的问题,我就会这样做。)

附加编辑:预览日志中的条目:

l.16 \begin{figure}
                   [h]
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
Missing character: There is no a in font nullfont!
./_region_.tex:27: Extra \endcsname.
\pgfutil@ifundefined ...@ifx \csname #1\endcsname 
                                                  \relax 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
Missing character: There is no a in font nullfont!
./_region_.tex:27: Extra \endcsname.
\pgfutil@ifundefined ...@ifx \csname #1\endcsname 
                                                  \relax 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);

./_region_.tex:27: Package pgf Error: No shape named `$(a' is known.

See the pgf package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Extra \endcsname.
<argument> ...$(a}\csname pgf@sh@ma@$(a\endcsname 
                                                  \csname pgf@sh@np@$(a\endc...
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
Missing character: There is no ( in font nullfont!
Missing character: There is no a in font nullfont!
./_region_.tex:27: Extra \endcsname.
<argument> ...ame \csname pgf@sh@np@$(a\endcsname 
                                                  \pgf@sh@reanchor {\csname ...
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pgf@sh@ns@ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Extra \endcsname.
<argument> ...hor@\csname pgf@sh@ns@$(a\endcsname 
                                                  @center
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Extra \endcsname.
\pgfutil@ifundefined ...@ifx \csname #1\endcsname 
                                                  \relax 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);

./_region_.tex:27: Package PGF Math Error: Unknown function `center' (in 'center').

See the PGF Math package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pgf@sh@ns@ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing } inserted.
<inserted text> 
                }
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
Missing character: There is no ( in font nullfont!
Missing character: There is no a in font nullfont!
./_region_.tex:27: Extra \endcsname.
<argument> ...hor@\csname pgf@sh@ns@$(a\endcsname 
                                                  @border\endcsname {\pgfqpo...
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
Missing character: There is no @ in font nullfont!
Missing character: There is no b in font nullfont!
Missing character: There is no o in font nullfont!
Missing character: There is no r in font nullfont!
Missing character: There is no d in font nullfont!
Missing character: There is no e in font nullfont!
Missing character: There is no r in font nullfont!
./_region_.tex:27: Extra \endcsname.
<argument> ...@ns@$(a\endcsname @border\endcsname 
                                                  {\pgfqpointpolar {\the \c@...
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pgf@sh@ns@ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Extra \endcsname.
<argument> \csname pgf@sh@ns@$(a\endcsname 
                                           
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Extra \endcsname.
\pgf@sh@reanchor ...me pgf@anchor@#1@#2\endcsname 
                                                  }
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Extra }, or forgotten $.
\pgf@sh@reanchor ...e pgf@anchor@#1@#2\endcsname }
                                                  
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing number, treated as zero.
<to be read again> 
                   \endcsname 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Illegal unit of measure (pt inserted).
<to be read again> 
                   \endcsname 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Extra \endcsname.
<recently read> \endcsname 
                           
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing number, treated as zero.
<to be read again> 
                   \global 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Illegal unit of measure (pt inserted).
<to be read again> 
                   \global 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pgf@sh@pi@ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
Missing character: There is no ( in font nullfont!
Missing character: There is no a in font nullfont!
./_region_.tex:27: Extra \endcsname.
\pgf@marshal ...s@ \pgf@sh@pi@ \pr@$ (a\endcsname 
                                                  \endcsname 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Extra \endcsname.
\pgf@marshal ...pi@ \pr@$ (a\endcsname \endcsname 
                                                  
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Undefined control sequence.
<argument> ...pointorigin \pgf@shape@original@pos 
                                                  
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Extra \endcsname.
\pgfutil@next ...@ns@\tikz@pp@name {#2}\endcsname 
                                                  \expandafter \ifx \csname ...
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing \endcsname inserted.
<to be read again> 
                   \pr@$ 
l.27     \path ($(a)
                    !0.5!(b)$) coordinate(c);

./_region_.tex:27: Package tikz Error: Giving up on this path. Did you forget a semicolon?.

See the tikz package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.27     \path ($(a)!
                     0.5!(b)$) coordinate(c);
./_region_.tex:27: Missing $ inserted.
<inserted text> 
                $
l.27     \path ($(a)!
                     0.5!(b)$) coordinate(c);
Missing character: There is no ! in font nullfont!
Missing character: There is no 0 in font nullfont!
Missing character: There is no . in font nullfont!
Missing character: There is no 5 in font nullfont!
Missing character: There is no ! in font nullfont!
Missing character: There is no ( in font nullfont!
Missing character: There is no b in font nullfont!
Missing character: There is no ) in font nullfont!
./_region_.tex:29: Missing $ inserted.
<inserted text> 
                $
l.29   \end{circuitikz}
                        \caption{Test circuit}
Preview: Tightpage -32891 -32891 32891 32891
./_region_.tex:31: Preview: Snippet 1 ended.(11449270+0x22609920).
<-><->
      
l.31 \end{figure}

答案1

我隐约记得预览和 tikz 总是因为处理和/或期望而出现一些问题$。我认为你有两个选择:

  1. 禁用textmath预览并获取 tikz 图形,或者
  2. 将您的 tikz 图形导出到文件中并将其作为图形重新包含回来。

对于 1.,在 Emacs 中看起来像这样: 在此处输入图片描述

对于 2,我创建了一个standalone-test.tex如下的新文件:

\documentclass[crop=true]{standalone}

\usepackage{siunitx}
\usepackage{amsmath}
\usepackage{circuitikz}
\usetikzlibrary{calc}
\newcommand{\marknode}[2][45]{%
  \node[circle, draw, red, inner sep=1pt,
    pin={[red, font=\tiny]#1:#2}
  ] at (#2.center) {};
}

\begin{document}

\begin{circuitikz}
  \def\dx{3} \def\dy{4} \draw (0,0) node[ground,name=gnd] {} (gnd)
  ++(0,\dy) coordinate(a) to[american voltage source,
    l_=$\begin{matrix} & + \\ & V_\textsc{s} \\ & \qty{10}{V} \\ & -
    \end{matrix}$,name=Vs] (gnd)
  (Vslabel) ++(-0.5,0) node[] {$I_\textsc{s} \big\uparrow$}
  ;
  \marknode{a} \marknode{Vslabel}
  \path (a) ++(\dx,0) coordinate(b);
  \marknode{b}
  \path ($(a)!0.5!(b)$) coordinate(c);
  \marknode{c}
\end{circuitikz}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

并将您的 .tex 文件更改为:

\documentclass{article}

\usepackage[textmath,displaymath,footnotes,sections,floats]{preview}

\usepackage{graphicx}

\begin{document}

Here we go with $a+b=c$.

\begin{figure}[h]
  \centering
  \includegraphics[page=1]{standalone-test}
  \caption{Test circuit}
  \label{fig:test-circuit}
\end{figure}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

在 Emacs 和预览中看起来像这样: 在此处输入图片描述

相关内容