Stop Press: tikzmarkevolui novamente

Stop Press: tikzmarkevolui novamente

Eu desenvolvi alguns pequenos comandos para ter uma bela "coisa de texto explicativo" para minhas anotações; considere o seguinte MWE (o problema também é explicado lá):

\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}

que produz uma coisa legal (IMHO):

Resultado do MWE

O problema é que às vezes é útil ter o \margincalloutcomandoanteso \roundmarkque define o nome do nó.

O documento exigirá duas passagens de qualquer maneira; Eu estava pensando que talvez fosse possível escrever algo como as referências futuras para o rótulo... mas não consigo encontrar nenhuma solução.

É possível referir-se a nós que serão resolvidos na próxima passagem?

ATUALIZAR:

Então tentei com tikzmark, mas deve haver algo estranho aqui. Olhar:

\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}

A primeira chamada (em texto) funciona, mas a linha não é traçada. E a segunda e terceira chamadas (aquela que marca os pontosemo gráfico) transformar toda a figura em sobreposição...

Ah...

O bom é que a chamada direta funciona, mas a linha não é traçada. Intrigado.

Responder1

(estou adicionando issoacimaporque substitui a resposta original e, portanto, alguém que procura apenas ao quee não se preocupe com ocomo,quando, e certamente não opor quenão deveria se preocupar em ler a resposta original.)

Stop Press: tikzmarkevolui novamente

tikzmarksofreu uma evolução considerável desde a sua criação, impulsionada principalmente pelas perguntas deste site. Um dos principais recursos que ele adquiriu ao longo do caminho foi a capacidade de usar as coordenadas salvas.anteriorà sua ocorrência no documento.

Um dos atributos que teve desde o início foi que se destinava a ser utilizadoforaum \tikzcomando ou tikzpictureambiente. Por dentro, o pensamento era: então alguém teria acesso total ao serviço normal de lembrança de coordenadas do TikZ e, portanto, não haveria necessidade de um arquivo \tikzmark.

No entanto, a característica principal acima mencionada énãoalgo que TikZ fornece. Não há como se referir a uma coordenada dentro de a tikzpictureantes de sua declaração. Então, se alguém quiser fazer isso, precisará de algo novo.

A principal característica desta questão é que o consulente deseja usar o mesmo mecanismo para se referir a coordenadas dentro e tikzpicturefora dele. Isso sugere que a maneira correta de fornecer essa capacidade de coordenação de clarividência dentro do tikzpictures é estender o tikzmark.

Isso acabou sendo bastante fácil. Resumindo, o que o tikzmark faz é associar um rótulo à origem de uma imagem tikz e todo o trabalho pesado é feito no sistema de coordenadas. A extensão é adicionar um deslocamento potencial, de modo que, uma vez que o tikz tenha descoberto onde está a origem da referida imagem tikz na página, ele aplica o deslocamento. Combine isso com um teste para ver se estamos dentro de uma imagem tikz e pronto.

(Vale a pena notar que se você mudar para esta nova versão, você deve excluir o arquivo aux antes de recompilar, caso contrário você receberá muitos erros na primeira recompilação.)

A sintaxedentrouma imagem tikz é \tikzmark{label}{coordinate}, por exemplo \tikmark{a}{(3,4)}. Isso significa que a coordenada (pic cs:a)apontará para o ponto (3,4)na imagem atual.

Você pode baixar esta nova versão do tikzmark emGitHub: baixe tikzmark.dtxe execute tex tikzmark.dtxpara gerar os arquivos.

Então com onovo, melhorado \tikzmark, o código voltou a um estado razoável mais uma vez:

\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}

(Mesma imagem abaixo)


A resposta original segue:

Algumas coisas aqui...

(Em primeiro lugar, encontrei um bug em tikzmarksua interação com marginpar. Suspeito que a versão com o bug seja mais recente que a versão no CTAN, pois você não deveria ter obtidoqualquer coisano seu segundo exemplo, se você estivesse usando a versão com bugs. De qualquer forma, uma versão atualizada édisponível no github.)

Em segundo lugar, e mais importante, \tikzmarknão foi concebido para ser utilizadodentroum tikzpictureambiente. As coisas dão errado se você fizer isso. É ainda mais sério do que usar regex para analisar HTML. A questão é que, se você estiver dentro de um tikzpictureambiente, terá acesso a todos os nós e materiais de posicionamento de coordenadas do tikz e não precisará do tikzmark.

(Veja bem, não parece importar quantas vezes eu digo "Não use tikzmark dentro de uma tikzpicture", as pessoas parecem querer usá-lo. Talvez eu deva aguentar e descobrir como fazê-lo funcionar. )

É certo que isso significa que você precisa de duas versões do seu código de texto explicativo: uma para quando a marca estiver em uma imagem tikz e outra quando não estiver. Provavelmente existem maneiras elegantes de codificar isso para evitar isso, mas sou um urso com pouco cérebro e não consigo pensar tão expansivamente neste momento.

Portanto, embora isso nunca ganhe um concurso de estilo, aqui está uma versão funcional do seu código com o que acho que deveria ser o resultado correto.

\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}

frases de destaque e tikzmark

informação relacionada