Menu

#354 [tixmark] has a problem with pgf

v1.0 (example)
open
nobody
5
2018-12-23
2015-02-25
Stefan
No

I run into a problem with tikzmark and the professional help on the xetex mail list and on stackexchange (Ulrike Fischer) identified it as a pgf problem. Please find some description and minimal examples here:

http://tex.stackexchange.com/questions/229500/tikzmark-and-xelatex

Discussion

  • Stefan

    Stefan - 2015-03-04

    For convenience, I attach the code here:

    The following code does not work when compiled with XeLaTeX but produces the expected result when compiled with PDFLaTeX:

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{tikzmark}
    
    \begin{document}
    
    x\pgfmark{tA}some text \pgfmark{tB} some text
    \begin{tikzpicture}[remember picture]
    \draw (0,0)node (A){A} rectangle (1,1)node (B){B};
    \end{tikzpicture}
    \begin{tikzpicture}[remember picture]
    \draw (0,0)node {\pgfmark{nA}} rectangle (1,1)node {\pgfmark{nB}};
    \end{tikzpicture}
    
    \vspace{3cm}\centering
    \begin{tikzpicture}[overlay,remember picture]
    \draw[red,->] (0,0)--(pic cs:tA) (0,0)--(pic cs:tB);
    \draw\[blue,->](0,0)--(pic cs:nA) (0,0)--(pic cs:nB); %nB faulty
    \draw\[green,->](0,0)--(A) (0,0)--(B);
    \end{tikzpicture}
    
    \end{document} 
    
     

    Last edit: Stefan Pinnow 2018-12-23
  • percusse

    percusse - 2015-05-23

    Hi Stefan

    tikzmark library is not actually an official library of TikZ but it is written by Andrew Stacey and he commented under your TeX.SX question under the nickname Loop Space what the problem is and how you can resolve.

    Maybe you can contact him for further elaborations?

     
    • Stefan

      Stefan - 2015-05-24

      Hi,

      I checked the Tex.SX post but did not find anything. I can contact him directly. Thanks for the hint!

      Best

      Stefan

       
  • cfr

    cfr - 2016-11-20

    The example given does not demonstrate the problem. Here's an example which uses tikzmark correctly (i.e. avoids nesting tikzpictures) by using \subnode within a node. With pdfTeX or LuaTeX, for example, this compiles correctly. With XeTeX, it does not.

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{tikzmark}
    \begin{document}
    \begin{tikzpicture}
      \node {An \subnode{p}{apple} a day makes all horses neigh.};
    \end{tikzpicture}
    
    \begin{tikzpicture}[remember picture, overlay]
        \draw [red] (p.north east) rectangle (p.south west);
    \end{tikzpicture}
    \end{document}
    

    The problem appears to lie in the backend driver provided by PGF. The following code corrects the problem (from Jipí's answer at http://tex.stackexchange.com/a/339975/).

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{tikzmark}
    % WORKAROUND:
    % Definition copied from pgfsys-common-pdf-via-dvi.def
    % http://tex.stackexchange.com/a/339975/
    % Compare http://tex.stackexchange.com/q/229500 and comments!
    \makeatletter
    \def\pgfsys@hboxsynced#1{%
      {%
        \pgfsys@beginscope%
        \setbox\pgf@hbox=\hbox{%
          \hskip\pgf@pt@x%
          \raise\pgf@pt@y\hbox{%
            \pgf@pt@x=0pt%
            \pgf@pt@y=0pt%
            \special{pdf: content q}%
            \pgflowlevelsynccm%
            \pgfsys@invoke{q -1 0 0 -1 0 0 cm}%
            \special{pdf: content -1 0 0 -1 0 0 cm q}% translate to original coordinate system
            \pgfsys@invoke{0 J [] 0 d}% reset line cap and dash
            \wd#1=0pt%
            \ht#1=0pt%
            \dp#1=0pt%
            \box#1%
            \pgfsys@invoke{n Q Q Q}%
          }%
          \hss%
        }%
        \wd\pgf@hbox=0pt%
        \ht\pgf@hbox=0pt%
        \dp\pgf@hbox=0pt%
        \pgfsys@hbox\pgf@hbox%
        \pgfsys@endscope%
      }%
    }
    \makeatother
    \begin{document}
    \begin{tikzpicture}
      \node {An \subnode{p}{apple} a day makes all horses neigh.};
    \end{tikzpicture}
    
    \begin{tikzpicture}[remember picture, overlay]
        \draw [red] (p.north east) rectangle (p.south west);
    \end{tikzpicture}
    \end{document}
    

    Examining the definition of this macro before it is redefined, it seems that the problem lies with its definition in pgfsys-dvipdfmx.def:

    \def\pgfsys@hboxsynced#1{%
      \pgfsys@beginscope%
        \setbox#1=\hbox{\box#1}%
        \wd#1=0pt%
        \ht#1=0pt%
        \dp#1=0pt%
        \pgfsys@dvipdfmx@suspendcontent%
        \pgfsys@invoke{0 J [] 0 d}% reset line cap and dash
        \pgfsys@dvipdfmx@start@force@reset@color%
        \pgf@sys@bp@correct\pgf@pt@x%
        \pgf@sys@bp@correct\pgf@pt@y%
        \special{pdf:btrans matrix \pgf@pt@aa\space \pgf@pt@ab\space \pgf@pt@ba\space \pgf@pt@bb\space 
          \pgf@sys@tonumber{\pgf@pt@x} \pgf@sys@tonumber{\pgf@pt@y}}%
        \box#1%
        \special{pdf:etrans}%
        \pgfsys@dvipdfmx@stop@force@reset@color%
        \pgfsys@dvipdfmx@unsuspendcontent%
      \pgfsys@endscope%
    }
    

    I don't understand this code at all, but according to comments on TeX SE, I gather that this is preventing positions within a node from being saved -- the position is always saved as 0,0. However, I may have misunderstood the discussion there. Even so, overwriting this definition with the one from pgfsys-common-pdf-via-dvi.def certainly makes the code work with XeTeX as it does with other engines.

     

    Last edit: Stefan Pinnow 2018-12-23
  • Stefan Pinnow

    Stefan Pinnow - 2018-12-23
    • labels: --> xelatex, tikzmark
    • summary: tixmark has a problem with pgf --> [tixmark] has a problem with pgf