Stop Press: tikzmarkvuelve a evolucionar

Stop Press: tikzmarkvuelve a evolucionar

He ideado un pequeño par de comandos para tener un bonito "texto" para mis notas; considere el siguiente MWE (el problema también se explica allí):

\documentclass{book}
\usepackage{tikz}
\tikzset{remember picture, 
    round mark/.style={
    circle, draw=yellow, minimum size=5mm, fill opacity=0.5, fill=yellow,
    },
}
\usepackage{pgfplots}\pgfplotsset{compat=1.9} 

\usepackage{siunitx}
\DeclareSIUnit{\krypt}{\ensuremath{\mathcal{K}r}}

\usepackage{xparse}
\newcommand{\roundmark}[1]{\tikz[overlay, remember picture, baseline=-0.5ex]
    \node [round mark, anchor=west] (#1) {};}
\NewDocumentCommand \addline {O{} m m }{%
    \begin{tikzpicture}[overlay,remember picture]
        \draw[ultra thick, yellow, ->, #1 ] (expl@#2) -- (#3);
    \end{tikzpicture}%
}
\NewDocumentCommand \margincallout {O{} m +m }{%
    \marginpar{
    \begin{tikzpicture}[overlay,remember picture]
        \node [ anchor=west, draw=orange, fill=yellow!20,  
            text width=\marginparwidth, align=left, font=\small, 
            #1 ] (expl@#2)
            at (0,0) {
                #3
            }; 
        \draw[ultra thick, yellow,->] (expl@#2) -- (#2);
\end{tikzpicture}}%
}

\begin{document}

I can mark thing in \roundmark{a}the main text and then have nice callouts from the marginpar to this point. 
\margincallout{a}{This is a callout, a nice one and it's ok.}

% thanks @bloodworks http://tex.stackexchange.com/a/62285/38080
% require package capt-of
\begin{figure}[htb]
        \begin{center}
            \begin{tikzpicture}[remember picture,
                ]
                \begin{axis}[
                        width=7cm,
                        xmin=0, xmax=10, domain=0:10,
                        enlarge y limits = 0.2,
                        ylabel = {Sensor R (\si{k\ohm})},
                        xlabel = {Kryporad (\si{\krypt})},
                        legend pos = north west, 
                        legend style={nodes=right},
                    ]
                    \addplot[red] {134 + 18.5*x + 15.0*sin(deg(0.664*x))};
                    \addplot[blue, dashed] {143 + 16.8*x};
                    \legend{non-linear fit, linear fit}
                \end{axis}
                \node [round mark] (hor-axis) at (4,-0.5) {}; 
                \node [round mark] (ver-axis) at (-0.5,4) {}; 
                %\draw (0,0) grid (5,5);
            \end{tikzpicture}
        \end{center}

        \caption{With a bit of guesswork I can mark things in the graphics, too}
        \label{fig:calibR}
\end{figure}
\margincallout[yshift=3cm]{hor-axis}{\textbf{Always} name the axis and columns, and use units when needed}
\addline{hor-axis}{ver-axis}

Uncomment the following to see the error: 


%But if I want to put the callout \textbf{before} the mark, 
%as in \margincallout{future}{A forward callout} it will not work, and give me an error. 

%The mark will be \roundmark{future}here, for example. 

\end{document}

lo que genera algo agradable (en mi humilde opinión):

Resultado del MWE

El problema es que a veces es útil tener la\margincallout comandoantesel \roundmarkque define el nombre del nodo.

El documento requerirá dos pases de todos modos; Estaba pensando que tal vez sea posible escribir algo como las referencias directas para la etiqueta... pero no encuentro ninguna solución.

¿Es posible hacer referencia a nodos que se resolverán en la próxima pasada?

ACTUALIZAR:

Así que lo intenté con tikzmark, pero debe haber algo extraño aquí. Mirar:

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{remember picture, 
    round mark/.style={
    circle, draw=yellow, minimum size=5mm, fill opacity=0.5, fill=yellow,
    },
}
\usepackage{pgfplots}\pgfplotsset{compat=1.9} 

\usepackage{siunitx}
\DeclareSIUnit{\krypt}{\ensuremath{\mathcal{K}r}}

\usepackage{xparse}
\newcommand{\rtikzmark}[1]{\tikzmark[{
    \node [baseline=-0.5ex, round mark, anchor=west]{}}]{#1}}
\NewDocumentCommand \addline {O{} m m }{%
    \begin{tikzpicture}[overlay,remember picture]
        \draw[ultra thick, yellow, ->, #1 ] (expl@#2) -- (pic  cs:#3);
    \end{tikzpicture}%
}
\NewDocumentCommand \margincallout {O{} m +m }{%
    \marginpar{
    \begin{tikzpicture}[overlay,remember picture]
        \node [ anchor=west, draw=orange, fill=yellow!20,  
            text width=\marginparwidth, align=left, font=\small, 
            #1 ] (expl@#2)
            at (0,0) {
                #3
            }; 
        \draw[ultra thick, yellow,->] (expl@#2) -- (pic cs: #2); 
\end{tikzpicture}}%
}

\begin{document}

I can mark thing in \rtikzmark{a}the main text and then have nice callouts from the marginpar to this point. 
\margincallout{a}{This is a callout, a nice one and it's ok.}

% thanks @bloodworks http://tex.stackexchange.com/a/62285/38080
% require package capt-of
\begin{figure}[htb]
        \begin{center}
            \begin{tikzpicture}[remember picture,
                ]
                \begin{axis}[
                        width=7cm,
                        xmin=0, xmax=10, domain=0:10,
                        enlarge y limits = 0.2,
                        ylabel = {Sensor R (\si{k\ohm})},
                        xlabel = {Kryporad (\si{\krypt})},
                        legend pos = north west, 
                        legend style={nodes=right},
                    ]
                    \addplot[red] {134 + 18.5*x + 15.0*sin(deg(0.664*x))};
                    \addplot[blue, dashed] {143 + 16.8*x};
                    \legend{non-linear fit, linear fit}
                \end{axis}
                \node [round mark] at (4,-0.5) {}; \tikzmark{hor-axis};
                \node [round mark] at (-0.5,4) {}; \tikzmark{ver-axis};
                %\draw (0,0) grid (5,5);
            \end{tikzpicture}
        \end{center}

        \caption{With a bit of guesswork I can mark things in the graphics, too}
        \label{fig:calibR}
\end{figure}
\margincallout[yshift=3cm]{hor-axis}{\textbf{Always} name the axis and columns, and use units when needed}
\addline{hor-axis}{ver-axis}

Uncomment the following to see the error: 


But if I want to put the callout \textbf{before} the mark, 
as in \margincallout{future}{A forward callout} it will not work, and give me an error. 

The mark will be \rtikzmark{future}here, for example. 

\end{document}

La primera llamada (en texto) funciona, pero luego no se traza la línea. Y la segunda y tercera convocatoria (la que marca puntosenel gráfico) transforma toda la figura en superposición...

Ach...

Lo bueno es que la llamada hacia adelante funciona, pero no se traza la línea. Perplejo.

Respuesta1

(Estoy agregando estoarribaporque reemplaza la respuesta original y, por lo tanto, alguien que busca solo laquéy no se preocupa por elcómo,cuando, y ciertamente no elpor quéNo debería molestarme en leer la respuesta original).

Stop Press: tikzmarkvuelve a evolucionar

tikzmarkha experimentado una evolución considerable desde sus inicios, impulsada principalmente por las preguntas de este sitio. Una de las características clave que adquirió en el camino fue la capacidad de utilizar las coordenadas que guardó.previoa su aparición en el documento.

Uno de sus atributos que ha tenido desde el principio fue que estaba pensado para ser utilizadoafueraun \tikzcomando o tikzpictureentorno. En el interior, la idea era que uno tendría acceso total al servicio normal de recuerdo de coordenadas de TikZ, por lo que no había necesidad de un archivo \tikzmark.

Sin embargo, la característica clave antes mencionada esnoalgo que proporciona TikZ. No hay una manera de hacer referencia a una coordenada dentro de tikzpictureantes de su declaración. Entonces, si uno quiere hacer eso, necesita algo nuevo.

La característica clave de esta pregunta es que el interrogante quiere utilizar el mismo mecanismo para referirse a las coordenadas dentro y tikzpicturefuera de él. Eso sugiere que la forma correcta de proporcionar esta capacidad de coordenadas de clarividencia dentro de tikzpictures es extender tikzmark.

Esto resultó ser bastante fácil. En resumen, lo que hace tikzmark es asociar una etiqueta con el origen de una imagen tikz y todo el trabajo pesado se realiza en el sistema de coordenadas. La extensión es agregar un desplazamiento potencial, de modo que una vez que tikz haya determinado en qué parte de la página está el origen de dicha imagen de tikz, aplique el desplazamiento. Combine eso con una prueba para ver si estamos dentro de una imagen tikz y listo.

(Vale la pena señalar que si cambia a esta nueva versión, debe eliminar el archivo auxiliar antes de volver a compilar, de lo contrario obtendrá muchos errores en la primera recompilación).

la sintaxisadentrouna imagen tikz es \tikzmark{label}{coordinate}, por ejemplo \tikmark{a}{(3,4)}. Esto significa que la coordenada (pic cs:a)apuntará al punto (3,4)de la imagen actual.

Puedes descargar esta nueva versión de tikzmark desdegithub: descargar tikzmark.dtxy ejecutar tex tikzmark.dtxpara generar los archivos.

Entonces con elmejorada \tikzmark, el código ahora vuelve a un estado razonable una vez más:

\documentclass{book}
%\url{http://tex.stackexchange.com/q/295903/86}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{remember picture, 
    round mark/.style={
    circle, draw=yellow, minimum size=5mm, fill opacity=0.5, fill=yellow,
    },
}
\usepackage{pgfplots}\pgfplotsset{compat=1.9} 

\usepackage{siunitx}
\DeclareSIUnit{\krypt}{\ensuremath{\mathcal{K}r}}

\usepackage{xparse}
\newcommand{\rtikzmark}[1]{\tikzmark[{
    \node [baseline=-0.5ex, round mark, anchor=west]{}}]{#1}}
\NewDocumentCommand \addline {O{} m m }{%
    \begin{tikzpicture}[overlay,remember picture]
        \draw[ultra thick, yellow, ->, #1 ] (expl@#2) -- (pic cs:#3);
    \end{tikzpicture}%
}

\NewDocumentCommand \margincallout {O{} m +m }{%
    \marginpar{
    \begin{tikzpicture}[overlay,remember picture]
        \node [ anchor=west, draw=orange, fill=yellow!20,  
            text width=\marginparwidth, align=left, font=\small, 
            #1 ] (expl@#2)
            at (0,0) {
                #3
            }; 
        \draw[ultra thick, yellow,->] (expl@#2) -- (pic cs:#2); 
\end{tikzpicture}}%
}

\begin{document}

I can mark thing in \rtikzmark{a}the main text and then have nice callouts from the marginpar to this point. 
\margincallout{a}{This is a callout, a nice one and it's ok.}

% thanks @bloodworks http://tex.stackexchange.com/a/62285/38080
% require package capt-of
\begin{figure}[htb]
        \begin{center}
            \begin{tikzpicture}[remember picture,
                ]
                \begin{axis}[
                        width=7cm,
                        xmin=0, xmax=10, domain=0:10,
                        enlarge y limits = 0.2,
                        ylabel = {Sensor R (\si{k\ohm})},
                        xlabel = {Kryporad (\si{\krypt})},
                        legend pos = north west, 
                        legend style={nodes=right},
                    ]
                    \addplot[red] {134 + 18.5*x + 15.0*sin(deg(0.664*x))};
                    \addplot[blue, dashed] {143 + 16.8*x};
                    \legend{non-linear fit, linear fit}
                \end{axis}
                \node [round mark] at (4,-0.5) (hor-axis) {};
                \node [round mark] at (-0.5,4) (ver-axis) {};
                \node [round mark] at (0,0) (origin) {};
                \tikzmark{hor-axis}{(hor-axis)}
                \tikzmark{ver-axis}{(ver-axis)}
                \tikzmark{origin}{(origin)}
                %\draw (0,0) grid (5,5);
            \end{tikzpicture}
        \end{center}

        \caption{With a bit of guesswork I can mark things in the graphics, too}
        \label{fig:calibR}
\end{figure}
\margincallout[yshift=4cm]{hor-axis}{\textbf{Always} name the axis and columns, and use units when needed}
\addline{hor-axis}{ver-axis}
\addline{hor-axis}{origin}

Uncomment the following to see the error: 


But if I want to put the callout \textbf{before} the mark, 
as in \margincallout{future}{A forward callout} it will not work, and give me an error. 

The mark will be \rtikzmark{future}here, for example. 

\end{document}

(La misma imagen que a continuación)


La respuesta original es la siguiente:

Algunas cosas aquí...

(En primer lugar, encontré un error tikzmarken su interacción con marginpar. Tengo la sospecha de que la versión con el error es más nueva que la versión en CTAN, ya que no debería haber obtenidocualquier cosaen su segundo ejemplo si estuviera usando la versión con errores. De todos modos, una versión actualizada esdisponible en github.)

En segundo lugar, y más importante, \tikzmarkno está diseñado para ser utilizadoadentroun tikzpictureambiente. Las cosas van mal si lo haces. Es incluso más serio que usar expresiones regulares para analizar HTML. El punto es que si estás dentro de un tikzpictureentorno, entonces tienes acceso a todos los nodos y coordenadas de posicionamiento de tikz y no necesitas tikzmark.

(Eso sí, no parece importar cuántas veces digo "No uses tikzmark dentro de una imagen tikz", la gente parece querer usarlo. Tal vez debería hacer de tripas corazón y descubrir cómo hacerlo funcionar. )

Es cierto que eso significa que necesitas dos versiones de tu código de llamada: una para cuando la marca está en una imagen tikz y otra cuando no lo está. Probablemente haya formas elegantes de codificar esto para evitarlo, pero soy un oso con poco cerebro y no puedo pensar tan expansivamente a esta hora.

Entonces, aunque esto nunca ganará en un concurso de estilo, aquí hay una versión funcional de su código con lo que creo que debería ser el resultado correcto.

\documentclass{book}
%\url{http://tex.stackexchange.com/q/295903/86}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{remember picture, 
    round mark/.style={
    circle, draw=yellow, minimum size=5mm, fill opacity=0.5, fill=yellow,
    },
}
\usepackage{pgfplots}\pgfplotsset{compat=1.9} 

\usepackage{siunitx}
\DeclareSIUnit{\krypt}{\ensuremath{\mathcal{K}r}}

\usepackage{xparse}
\newcommand{\rtikzmark}[1]{\tikzmark[{
    \node [baseline=-0.5ex, round mark, anchor=west]{}}]{#1}}
\NewDocumentCommand \addline {O{} m m }{%
    \begin{tikzpicture}[overlay,remember picture]
        \draw[ultra thick, yellow, ->, #1 ] (expl@#2) -- (pic cs:#3);
    \end{tikzpicture}%
}

\NewDocumentCommand \addlineb {O{} m m }{%
    \begin{tikzpicture}[overlay,remember picture]
        \draw[ultra thick, yellow, ->, #1 ] (expl@#2) -- (#3);
    \end{tikzpicture}%
}


\NewDocumentCommand \margincallout {O{} m +m }{%
    \marginpar{
    \begin{tikzpicture}[overlay,remember picture]
        \node [ anchor=west, draw=orange, fill=yellow!20,  
            text width=\marginparwidth, align=left, font=\small, 
            #1 ] (expl@#2)
            at (0,0) {
                #3
            }; 
        \draw[ultra thick, yellow,->] (expl@#2) -- (pic cs:#2); 
\end{tikzpicture}}%
}

\NewDocumentCommand \margincalloutb {O{} m +m }{%
    \marginpar{
    \begin{tikzpicture}[overlay,remember picture]
        \node [ anchor=west, draw=orange, fill=yellow!20,  
            text width=\marginparwidth, align=left, font=\small, 
            #1 ] (expl@#2)
            at (0,0) {
                #3
            }; 
        \draw[ultra thick, yellow,->] (expl@#2) -- (#2); 
\end{tikzpicture}}%
}

\begin{document}

I can mark thing in \rtikzmark{a}the main text and then have nice callouts from the marginpar to this point. 
\margincallout{a}{This is a callout, a nice one and it's ok.}

% thanks @bloodworks http://tex.stackexchange.com/a/62285/38080
% require package capt-of
\begin{figure}[htb]
        \begin{center}
            \begin{tikzpicture}[remember picture,
                ]
                \begin{axis}[
                        width=7cm,
                        xmin=0, xmax=10, domain=0:10,
                        enlarge y limits = 0.2,
                        ylabel = {Sensor R (\si{k\ohm})},
                        xlabel = {Kryporad (\si{\krypt})},
                        legend pos = north west, 
                        legend style={nodes=right},
                    ]
                    \addplot[red] {134 + 18.5*x + 15.0*sin(deg(0.664*x))};
                    \addplot[blue, dashed] {143 + 16.8*x};
                    \legend{non-linear fit, linear fit}
                \end{axis}
                \node [round mark] at (4,-0.5) (hor-axis) {};
                \node [round mark] at (-0.5,4) (ver-axis) {};
                \node [round mark] at (0,0) (origin) {};
                %\draw (0,0) grid (5,5);
            \end{tikzpicture}
        \end{center}

        \caption{With a bit of guesswork I can mark things in the graphics, too}
        \label{fig:calibR}
\end{figure}
\margincalloutb[yshift=4cm]{hor-axis}{\textbf{Always} name the axis and columns, and use units when needed}
\addlineb{hor-axis}{ver-axis}
\addlineb{hor-axis}{origin}

Uncomment the following to see the error: 


But if I want to put the callout \textbf{before} the mark, 
as in \margincallout{future}{A forward callout} it will not work, and give me an error. 

The mark will be \rtikzmark{future}here, for example. 

\end{document}

llamadas y tikzmark

información relacionada