Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\verb is omitted from anchor example code? #1267

Closed
hbghlyj opened this issue Jul 24, 2023 · 5 comments · Fixed by #1269
Closed

\verb is omitted from anchor example code? #1267

hbghlyj opened this issue Jul 24, 2023 · 5 comments · Fixed by #1269
Labels

Comments

@hbghlyj
Copy link

hbghlyj commented Jul 24, 2023

Version

3.1.10

Details

In manual §13.2.3 anchor example code:

\usetikzlibrary {arrows.meta}
\begin{tikzpicture}
\node (shape) at (0,2) [draw] {|class Shape|};
\node (rect) at (-2,0) [draw] {|class Rectangle|};
\node (circle) at (2,0) [draw] {|class Circle|};
\node (ellipse) at (6,0) [draw] {|class Ellipse|};
\draw (node cs:name=circle,anchor=north) |- (0,1);
\draw (node cs:name=ellipse,anchor=north) |- (0,1);
\draw [arrows = -{Triangle[open, angle=60:3mm]}]
(node cs:name=rect,anchor=north)
|- (0,1) -| (node cs:name=shape,anchor=south);
\end{tikzpicture}

I compile this code with PDFLaTeX, the output is different from the manual:
image

After replacing | with \verb| the output is same as the manual:
canvas

@hbghlyj hbghlyj added the manual label Jul 24, 2023
@hbghlyj hbghlyj changed the title in anchor example \verb is omitted ? \verb is omitted from anchor example code? Jul 24, 2023
@muzimuzhi
Copy link
Member

muzimuzhi commented Jul 25, 2023

I compile this code with PDFLaTeX, the output is different from the manual:

Which document class did you use?

pgfmanual.tex loads ltxdoc.cls which sets

\AtBeginDocument{\MakeShortVerb{\|}}

An ltxdoc example

\documentclass{ltxdoc}

\begin{document}
normal text
|verb text|
\end{document}

image

PS: The command \MakeShortVerb is provided by doc.sty. It's also available from a sole package shortvrb (see texdoc doc (v3.0m, 2022/11/13), sec. 2.14 "Short input of verbatim text pieces".

\documentclass{article}
\usepackage{shortvrb}
\MakeShortVerb{\|}

\begin{document}
normal text
|verb text|
\end{document}

@muzimuzhi muzimuzhi closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2023
@muzimuzhi
Copy link
Member

muzimuzhi commented Jul 25, 2023

When used as part of a node text, both the short verb |...| and (long) verb \verb|...| forms can't really typeset the content in verbatim (the content is already tokenized), but only in (the current) typewriter font family.

For the sake of

using node font=\ttfamily here (and for all similar codeexamples) seems better. @hmenke opinions?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}[node font=\ttfamily]
  \node (shape)   at (0,2)  [draw] {class Shape};
  \node (rect)    at (-2,0) [draw] {class Rectangle};
  \node (circle)  at (2,0)  [draw] {class Circle};
  \node (ellipse) at (6,0)  [draw] {class Ellipse};

  \draw (node cs:name=circle,anchor=north) |- (0,1);
  \draw (node cs:name=ellipse,anchor=north) |- (0,1);
  \draw [arrows = -{Triangle[open, angle=60:3mm]}]
           (node cs:name=rect,anchor=north)
        |- (0,1) -| (node cs:name=shape,anchor=south);
\end{tikzpicture}
\end{document}

@hmenke
Copy link
Member

hmenke commented Jul 25, 2023

Verbatim material inside node text does work. The parser uses \setbox specifically to work around the tokenization problem.

\def\tikz@do@fig{%
% Ok, reset all node part boxes
\pgfutil@for\tikz@temp:=\tikz@nodepart@list\do{%
\expandafter\setbox\csname pgfnodepart\tikz@temp box\endcsname=\box\pgfutil@voidb@x%
}%
\setbox\pgfnodeparttextbox=\hbox%
\bgroup%
\pgfinterruptpicture%
\pgfsys@begin@text%
\pgfsys@text@to@black@hook%
\tikzset{every text node part/.try}%
\ifx\tikz@textopacity\pgfutil@empty%
\else%
\pgfsetfillopacity{\tikz@textopacity}%
\pgfsetstrokeopacity{\tikz@textopacity}%
\fi%
\ifx\tikz@text@width\pgfutil@empty%
\tikz@textfont%
\else%
\begingroup%
\pgfmathsetlength{\pgf@x}{\tikz@text@width}%
\pgfutil@minipage[t]{\pgf@x}\leavevmode\hbox{}%
\tikz@textfont%
\tikz@text@action%
\fi%
\tikz@atbegin@node%
\bgroup%
\aftergroup\unskip%
% Some color stuff has been moved from here to outside; this is
% necessary for support of dvisvgm and of animation
% snapshots.
\ifx\tikz@textcolor\pgfutil@empty%
\else%
\pgfutil@colorlet{.}{\tikz@textcolor}%
\pgfutil@color{\tikz@textcolor}%
\fi%
\setbox\tikz@figbox=\box\pgfutil@voidb@x%
\setbox\tikz@figbox@bg=\box\pgfutil@voidb@x%
\tikz@uninstallcommands%
\iftikz@handle@active@code%
\tikz@orig@shorthands%
\let\tikz@orig@shorthands\pgfutil@empty%
\fi%
\ifnum\the\catcode`\;=\active\relax\expandafter\let\tikz@activesemicolon=\tikz@origsemi\fi%
\ifnum\the\catcode`\:=\active\relax\expandafter\let\tikz@activecolon=\tikz@origcolon\fi%
\ifnum\the\catcode`\|=\active\relax\expandafter\let\tikz@activebar=\tikz@origbar\fi%
\aftergroup\tikz@fig@collectresetcolor%
\tikz@signal@halign@check%
\tikz@text@reset%
\tikz@halign@check%
\ignorespaces%
}%

@muzimuzhi
Copy link
Member

Ah you're right! Then the codeexample(s) using |...| as short verb may need sth like

\begin{codeexample}[preamble={\usepackage{shortvrb} \MakeShortVerb{\|}}]

Or, as originally suggested, use \verb|...| instead.

@hmenke
Copy link
Member

hmenke commented Jul 25, 2023

Since no actual verbatim is required for the example, I prefer your proposal of simply changing the node font to \ttfamily.

muzimuzhi added a commit to muzimuzhi/pgf that referenced this issue Jul 26, 2023
muzimuzhi added a commit to muzimuzhi/pgf that referenced this issue Jul 26, 2023
Signed-off-by: muzimuzhi <muzimuzhi@gmail.com>
@muzimuzhi muzimuzhi mentioned this issue Jul 26, 2023
2 tasks
@muzimuzhi muzimuzhi linked a pull request Jul 26, 2023 that will close this issue
2 tasks
loopspace pushed a commit to loopspace/pgf that referenced this issue Apr 2, 2024
Signed-off-by: muzimuzhi <muzimuzhi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants