% \iffalse meta-comment %<*internal> \iffalse % %<*readme> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * hf-tikz --- A simple way to highlight formulas and formula parts. * * E-mail: claudio dot fiandrino at gmail dot com * * Released under the LaTeX Project Public License v1.3c or later * * See http://www.latex-project.org/lppl.txt * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * The package provides a way to highlight formulas and formula parts in both documents and presentations thanks to TikZ. % %<*internal> \fi \def\nameofplainTeX{plain} \ifx\fmtname\nameofplainTeX\else \expandafter\begingroup \fi % %<*install> \input docstrip.tex \keepsilent \askforoverwritefalse \preamble * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * hf-tikz --- A simple way to highlight formulas and formula parts. * * E-mail: claudio dot fiandrino at gmail dot com * * Released under the LaTeX Project Public License v1.3c or later * * See http://www.latex-project.org/lppl.txt * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \endpreamble \postamble Copyright (C) 2012-2014 by Claudio Fiandrino This work may be distributed and/or modified under the conditions of the LaTeX Project Public License (LPPL), either version 1.3c of this license or (at your option) any later version. The latest version of this license is in the file: http://www.latex-project.org/lppl.txt This work is "maintained" (as per LPPL maintenance status) by Claudio Fiandrino. This work consists of the file hf-tikz.dtx and the derived files hf-tikz.ins and hf-tikz.pdf hf-tikz.sty. \endpostamble \usedir{tex/latex/hf-tikz} \generate{ \file{\jobname.sty}{\from{\jobname.dtx}{package}} } % %\endbatchfile %<*internal> \generate{ \file{\jobname.ins}{\from{\jobname.dtx}{install}} } \nopreamble\nopostamble \generate{ \file{README.txt}{\from{\jobname.dtx}{readme}} } \ifx\fmtname\nameofplainTeX \expandafter\endbatchfile \else \expandafter\endgroup \fi % %<*package> \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{hf-tikz}[2014/07/25 v0.3a A simple way to highlight formulas and formula parts.] % %<*driver> \documentclass{ltxdoc} \usepackage[T1]{fontenc} \usepackage{csquotes} \usepackage{lmodern} \usepackage{amsmath,amssymb} \usepackage[width=14cm]{geometry} \usepackage{charter,pxfonts} \usepackage[customcolors,shade,markings]{\jobname} \usetikzlibrary{calc} \usepackage{hypdoc} \newcommand{\library}[1]{\textcolor{red!80!black}{\texttt{#1}}} \newcommand{\packoption}[2]{\textcolor{blue!60!cyan}{\texttt{#1}} \texttt{(initial:~#2)}} \newcommand{\smkey}[1]{\textcolor{blue!60!cyan}{\texttt{#1}}} \newcommand{\smoption}[1]{\textcolor{orange!30!red}{\texttt{#1}}} \newcommand{\hftikz}{\textsf{hf-tikz}} \EnableCrossrefs \CodelineIndex \RecordChanges \begin{document} \DocInput{\jobname.dtx} \end{document} % % \fi % % \CheckSum{482} % % \CharacterTable % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z % Digits \0\1\2\3\4\5\6\7\8\9 % Exclamation \! Double quote \" Hash (number) \# % Dollar \$ Percent \% Ampersand \& % Acute accent \' Left paren \( Right paren \) % Asterisk \* Plus \+ Comma \, % Minus \- Point \. Solidus \/ % Colon \: Semicolon \; Less than \< % Equals \= Greater than \> Question mark \? % Commercial at \@ Left bracket \[ Backslash \\ % Right bracket \] Circumflex \^ Underscore \_ % Grave accent \` Left brace \{ Vertical bar \| % Right brace \} Tilde \~} % % \changes{v0.1}{2012/08/17}{Initial version} % \changes{v0.1a}{2012/12/18}{Fixed bug \pgfpointorigin} % \changes{v0.2}{2013/01/13}{Added norndcorners and warning second run} % \changes{v0.3}{2013/03/01}{Key interface and markings option} % \changes{v0.3}{2014/07/25}{Documentation} % % \GetFileInfo{hf-tikz.sty} % % \title{The \textsf{hf-tikz} package\thanks{This document % corresponds to \textsf{hf-tikz}~\fileversion, % dated \filedate.}} % \author{Claudio Fiandrino\thanks{e-mail: \texttt{claudio dot fiandrino at gmail dot com}}} % \maketitle % \begin{abstract} % This package provides a way to \emph{highlight} formulas in both documents and presentations thanks to Ti\emph{k}Z. % The idea originated in \href{http://tex.stackexchange.com/questions/52598/beamer-highlighting-aligned-math-with-overlay}{this question} on \href{http://tex.stackexchange.com}{TeX.StackExchange} % and it is based on the \texttt{tikzmark} macro from \href{http://tex.stackexchange.com/users/86/andrew-stacey}{Andrew Stacey} and %\href{http://tex.stackexchange.com/users/4301/peter-grill}{Peter Grill}. % % \end{abstract} % \tableofcontents % % \section{Introduction and requirements} % The aim of the package is to provide a simple way to highlight formulas. \hftikz\ is not the first package that tries to accomplish this task, but, despite \href{http://www.ctan.org/pkg/empheq}{empheq}, it provides not only a way to highlight formulas in standard document, but also inside a presentation though Beamer overlay-aware specifications. In addition, with respect to \href{http://www.ctan.org/pkg/empheq}{empheq}, \hftikz\ even allows to highlight just a part of a formula. % % The package uses Ti\emph{k}Z and it is based on the \texttt{tikzmark} macro from \href{http://tex.stackexchange.com/users/86/andrew-stacey}{Andrew Stacey} and %\href{http://tex.stackexchange.com/users/4301/peter-grill}{Peter Grill} (see \href{http://tex.stackexchange.com/questions/51582/background-coloring-with-overlay-specification-in-algorithm2e-beamer-package}{this answer} and \href{http://tex.stackexchange.com/questions/50015/tikzmark-to-have-different-behaviour-if-first-run-and-mark-locations-not-yet-av}{this question}): among the numerous versions present on \href{http://tex.stackexchange.com}{TeX.SX}, the one the package implements is taken from \href{http://tex.stackexchange.com/questions/57537/issues-and-potentiality-of-the-tikzmark-macro-dynamic-box-adaptation#57655}{this answer}. Indeed, as explained later, the concept of \emph{extendible markers} helps a lot in customizing the box dimension. % % The packages loaded by \hftikz\ are: % \begin{itemize} % \item Ti\emph{k}Z and the libraries \library{shadings} and \library{decorations.markings} (this library is not always loaded, see subsection \ref{subsec:markings}); % \item \textsf{xparse}; % \item \textsf{etoolbox}. % \end{itemize} % % % \section{Using the package} % \subsection{The basic commands} % Formulas can be highlighted by inserting a pair of delimiters before and % after the part to be highlighted. Two compilation runs are always necessary: the first one to compute the position of the delimiters (also called markers in this manual) and the second one to actually place the box. % \DescribeMacro{\tikzmarkin}^^A % The starting delimiter should be introduced with the \cs{tikzmarkin} macro: it may assume a different syntax upon % being in \texttt{beamer} mode or not as it will be pointed out in subsection \ref{subsec:beamer}. % % \DescribeMacro{\tikzmarkend}^^A % The end delimiter should be introduced by means of the \cs{tikzmarkend} macro: despite \cs{tikzmarkin}, % this macro keeps the same syntax in \texttt{beamer} mode too. % % An example of the basic use is: % \begin{verbatim} % \[x+\tikzmarkin{a}y\tikzmarkend{a}=400\] % \end{verbatim} % which produces: % \[x+\tikzmarkin{a}y\tikzmarkend{a}=400\] % % Notice that the delimiter labels, also called \texttt{marker-id}s, should characterize \emph{uniquely} the part highlighted. Reusing the same name more than once will lead to undesired results. Along this documentation there are examples that illustrates some guidelines to provide names consistenly. % % In presence of fractions, sums, integrals and other operators, the standard command is not appropriate. Consider the following example: % \begin{verbatim} % \[\tikzmarkin{a-1}x+\dfrac{z}{y}=400\tikzmarkend{a-1}\] % \end{verbatim} % It leads to: % \[\tikzmarkin{a-1}x+\dfrac{z}{y}=400\tikzmarkend{a-1}\] % In this case, the user must specify manually which are the \emph{shift-offsets} that delimits the box: % \begin{verbatim} % \begin{equation} % \tikzmarkin{right delim frac}(0.1,-0.4)(-0.1,0.5) % x+\dfrac{z}{y}=400 % \tikzmarkend{right delim frac} % \end{equation} % \end{verbatim} % and this fixes the problem: % \begin{equation} % \tikzmarkin{right delim frac}(0.1,-0.4)(-0.1,0.5) % x+\dfrac{z}{y}=400 % \tikzmarkend{right delim frac} % \end{equation} % % The \emph{shift-offsets} should be introduced using the following syntax: % \begin{verbatim} % \tikzmarkin{marker-id}(below right offset)(above left offset) % \end{verbatim} % % The following image explains pretty well the difference between the default setting and the \emph{shift-offsets} used in the previous example: % \bigskip % \begin{center} % \tikzmarkin{r}(0.1,-0.4)(-0.1,0.5)\tikz[baseline=-0.5ex]\node[opacity=0]{\ensuremath{x+\dfrac{z}{y}=400}};\tikzmarkend{r} % $ % \qquad % x+\dfrac{z}{y}=400 % \qquad % $ % \tikzmarkin{f}\tikz[baseline=-0.5ex]\node[opacity=0]{\ensuremath{x+\dfrac{z}{y}=400}};\tikzmarkend{f} % \end{center} % \begin{tikzpicture}[remember picture,overlay] % \foreach \coord in {pic cs:r,pic cs:f} % \draw plot[mark=x] coordinates{(\coord)} node[left]{\scriptsize{\texttt{\coord}}}; % % \draw plot[mark=x] coordinates{($(pic cs:r)+(0.1,-0.4)$)} node[below]{\scriptsize{\texttt{(0.1,-0.4)}}}; % \draw plot[mark=x] coordinates{(r)} node[above]{\scriptsize{\texttt{(-0.1,0.5)}}}; % % \draw plot[mark=x] coordinates{($(pic cs:f)+(0.1,-0.18)$)} node[below]{\scriptsize{\texttt{default setting}}}; % \draw plot[mark=x] coordinates{(f)} node[above]{\scriptsize{\texttt{default setting}}}; % \end{tikzpicture} % % Manual shifts allow to customize the box dimension on the base of user's needs: they should be introduced inside round braces as coordinate points. Coordinates, indeed, provide more degree of freedom from the user's point of view whereas other solutions are more restrictive. Markers, therefore, are \emph{extensible}. Notice that with the aformentioned syntax, it is not possible to use the markers separately, but they should be declared in pair. % % From version 0.3, it is also possible to exploit a key-based interface to set the \emph{shift-offsets}; for example, the previous example, could have been done as follows: % \begin{verbatim} % \begin{equation} % \tikzmarkin[below right offset={0.1,-0.4},above left offset={-0.1,0.5}] % {right delim frac 2} % x+\dfrac{z}{y}=400 % \tikzmarkend{right delim frac 2} % \end{equation} % \end{verbatim} % leads to: % \begin{equation} % \tikzmarkin[below right offset={0.1,-0.4},above left offset={-0.1,0.5}]{right delim frac 2} % x+\dfrac{z}{y}=400 % \tikzmarkend{right delim frac 2} % \end{equation} % % The list of keys available to customize the \emph{shift-offsets} are: % \begin{itemize} % \item \packoption{left}{-0.1/-0.075}: this key sets the left offset (the second value is active when the \smoption{fill} option is passed to the package); % % \item \packoption{right}{0.1/0.075}: this key sets the right offset (the second value is active when the \smoption{fill} option is passed to the package); % % \item \packoption{above}{0.35}: this key sets the above offset; % % \item \packoption{below}{-0.18}: this key sets the below offset; % % \item \packoption{below right}{0.1/0.075,0.35}: this key sets contemporarely the below and the right offsets; % % \item \packoption{above left}{-0.1/-0.075,0.35}: this key sets contemporarely the above and the left offsets. % % \end{itemize} % % All the keys, not only the ones devoted to the \emph{shift-offsets}, should be introduced in the first optional argument only if the \smoption{beamer} option is not loaded. In the other case, the first argument of \verb|\tikzmarkin| concerns the overly-specification definition. Furthermore, the keys provided in the optional argument have a local scope. On the contrary, when they are set by means of \verb|\tikzset{}|, they are applied to the whole document. For example: % \begin{verbatim} % \tikzset{above left offset={-0.1,0.325},below right offset={0.1,-0.4}} % \end{verbatim} % % \subsection{An advanced example} % This example shows how to insert an annotation aligned with a sentence: it requires the \library{calc} library from Ti\emph{k}Z. The colors have been set accordingly to the explanation provided in subsection \ref{subsec:customcolors}. % \hfsetfillcolor{red!10} % \hfsetbordercolor{red} % \begin{equation*} % \left.\begin{array}{cc} % -2\cdot \tikzmarkin{col}(0.05,-0.3)(-0.05,0.4)2=& -4 \\ % -2\cdot 1=& -2 \\ % -2\cdot 0\tikzmarkend{col}=& 0 % \end{array}\right\} \text{\small Product increases by 2 each time.} % \end{equation*} % \begin{tikzpicture}[remember picture,overlay] % \coordinate (col-aa) at ($(col)+(1.825,-1.8)$); % \node[align=left,right] at (col-aa) {\small{Annotation}}; % \path[-stealth,red,draw] (col-aa) -| ($(col)+(0.14,-1.55)$); % \end{tikzpicture} % \linebreak % % The code is: % \begin{verbatim} % \begin{equation*} % \left.\begin{array}{cc} % -2\cdot \tikzmarkin{col}(0.05,-0.3)(-0.05,0.4)2=& -4 \\ % -2\cdot 1=& -2 \\ % -2\cdot 0\tikzmarkend{col}=& 0 % \end{array}\right\} \text{\small Product increases by 2 each time.} % \end{equation*} % % % To insert the annotation % \begin{tikzpicture}[remember picture,overlay] % % adjust the shift from "col" to move the position of the annotation % \coordinate (col-aa) at ($(col)+(1.825,-1.8)$); % \node[align=left,right] at (col-aa) {\small{Annotation}}; % \path[-stealth,red,draw] (col-aa) -| ($(col)+(0.14,-1.55)$); % \end{tikzpicture} % \end{verbatim} % % Note that when a formula is highlighted, the \texttt{marker-id} can be used to subsequently add elements on the image, i.e. annotations. % % From the version 0.3, it exists simpler manner to add annotations that requires the option \smoption{markings} to be enabled. Under such an hypothesis, the previous example can be done as follows (the annotation has been put a little bit close to the highlighted area intentionally): % \begin{equation*} % \left.\begin{array}{cc} % -2\cdot \tikzmarkin[mark at=0.93]{col 1}(0.05,-0.2)(-0.05,0.4)2=& -4 \\ % -2\cdot 1=& -2 \\ % -2\cdot 0\tikzmarkend{col 1}=& 0 % \end{array}\right\} \text{\small Product increases by 2 each time.} % \end{equation*} % \begin{tikzpicture}[remember picture,overlay] % \coordinate (col-aa) at ($(col 1)+(1.3,-1.8)$); % \node[align=left,right] at (col-aa) {\small{Annotation}}; % \path[-stealth,red,draw,use marker id] (col-aa) -| (0,0); % \end{tikzpicture} % \linebreak % % The code: % \begin{verbatim} % \begin{equation*} % \left.\begin{array}{cc} % -2\cdot \tikzmarkin[mark at=0.93]{col 1}(0.05,-0.2)(-0.05,0.4)2=& -4 \\ % -2\cdot 1=& -2 \\ % -2\cdot 0\tikzmarkend{col 1}=& 0 % \end{array}\right\} \text{\small Product increases by 2 each time.} % \end{equation*} % \begin{tikzpicture}[remember picture,overlay] % \coordinate (col-aa) at ($(col 1)+(1.3,-1.8)$); % \node[align=left,right] at (col-aa) {\small{Annotation}}; % \path[-stealth,red,draw,use marker id] (col-aa) -| (0,0); % \end{tikzpicture} % \end{verbatim} % % Thus, it is sufficient to mark the box delimiting the highlighted area with the option \smkey{mark at}. Then, it is possible to access this coordinate by means of \smkey{use marker id}. Further details are provided in subsection \ref{subsec:markings}. % % \section{The options} % \subsection{The \texttt{beamer} mode}\label{subsec:beamer} % \DescribeMacro{beamer}^^A % The call: % \begin{verbatim} % \usepackage[beamer]{hf-tikz} % \end{verbatim} % let the package to enter in \texttt{beamer} mode and the \cs{tikzmarkin} macro becomes \emph{overlay-aware}. As a resutl, overlay specifications can be introduced as first argument. For example: % \begin{verbatim} % \begin{align} % \tikzmarkin<1->{a1}a_i\tikzmarkend{a1} + b_j = 10 \\ % \tikzmarkin<3>{c}c_j + d_j + % \tikzmarkin<2>{b}a_i\tikzmarkend{b} % >= 30\tikzmarkend{c} % \end{align} % \end{verbatim} % Here it follows a list of examples in which overlay-specifications can be defined: % \begin{itemize} % \item a single number: \texttt{<1>}; % \item multiple numbers separated by commas and delimited by braces: \texttt{<\{1,2,3\}>}; % \item a single number followed by a dash: \texttt{<1->}. % \end{itemize} % % \subsection{Customize colors}\label{subsec:customcolors} % \DescribeMacro{customcolors}^^A % This option allows to customize both the fill and the border color. While using this option, two commands become available: % \begin{itemize} % \item \cs{hfsetfillcolor} % \item \cs{hfsetbordercolor} % \end{itemize} % These commands can be used at any time in the document. For example: % \begin{verbatim} % \hfsetfillcolor{red!10} % \hfsetbordercolor{red} % \[ % \tikzmarkin{z}(0.2,-0.4)(-0.2,0.6) % \dfrac{100}{x} % \tikzmarkend{z} % \] % \end{verbatim} % produces: % \hfsetfillcolor{red!10} % \hfsetbordercolor{red} % \[\tikzmarkin{z}(0.2,-0.4)(-0.2,0.6)\dfrac{100}{x}\tikzmarkend{z}\] % Then: % \begin{verbatim} % \hfsetfillcolor{blue!10} % \hfsetbordercolor{blue} % \[\tikzmarkin{z1}x+y=400\tikzmarkend{z1}\] % \end{verbatim} % gives: % \hfsetfillcolor{blue!10} % \hfsetbordercolor{blue} % \[\tikzmarkin{z1}x+y=400\tikzmarkend{z1}\] % % From the version 0.3, it is also possible to customize the fill and the border color by means of the following keys: % \begin{itemize} % \item \packoption{set fill color}{fancybrown}: this key sets the fill color; % \item \packoption{set border color}{fancyviolet}: this key sets the border color. % \end{itemize} % % An example: % \begin{verbatim} % \[ % \tikzmarkin[set fill color=green!50!lime!30, % set border color=green!40!black]{z-a}(0.2,-0.4)(-0.2,0.6) % \dfrac{100}{x} % \tikzmarkend{z-a} % \] % \end{verbatim} % The result: % \[\tikzmarkin[set fill color=green!50!lime!30,set border color=green!40!black]{z-a}(0.2,-0.4)(-0.2,0.6)\dfrac{100}{x}\tikzmarkend{z-a}\] % % Notice that: % \begin{itemize} % \item the color definition can also be done via \cs{tikzset}; in this case its application is global in the document % \begin{verbatim} % \tikzset{set fill color=orange!30,set border color=orange} % \end{verbatim} % \item global definitions defined via \cs{tikzset} or \cs{hfsetfillcolor} and \cs{hfsetbordercolor} can always be overridden by local ones; that is: % \end{itemize} % \begin{verbatim} % \tikzset{set fill color=orange!30,set border color=orange} % \[ % \tikzmarkin[set fill color=green!50!lime!30, % set border color=green!40!black]{label}(0.2,-0.4)(-0.2,0.6) % \dfrac{100}{x} % \tikzmarkend{z-a} % \] % \end{verbatim} % still gives: % \tikzset{set fill color=orange!30,set border color=orange} % \[ % \tikzmarkin[set fill color=green!50!lime!30,set border color=green!40!black]{lab}(0.2,-0.4)(-0.2,0.6) % \dfrac{100}{x} % \tikzmarkend{lab} % \] % % \subsection{Using shadings} % \DescribeMacro{shade}^^A % \hfsetfillcolor{blue!10} % \hfsetbordercolor{blue} % The option \smoption{shade} activates the possibility of introducing shaded backgrounds besides any fill color definition currently set up. Available shadings are: % \begin{itemize} % \item vertical shading; % \item horizontal shading; % \item radial shading. % \end{itemize} % % \subsubsection*{Example with vertical shading} % Code: % \begin{verbatim} % \[ % \tikzmarkin[top color=white, bottom color=blue!20]{vshade} % x+y=400 % \tikzmarkend{vshade} % \] % \end{verbatim} % Result: % \[\tikzmarkin[top color=white, bottom color=blue!20]{vshade}x+y=400\tikzmarkend{vshade}\] % % \subsubsection*{Example with horizontal shading} % Code: % \begin{verbatim} % \[ % \tikzmarkin[left color=white, right color=blue!20]{hoshade} % x+y=400 % \tikzmarkend{hoshade} % \] % \end{verbatim} % Result: % \[\tikzmarkin[left color=white, right color=blue!20]{hoshade}x+y=400\tikzmarkend{hoshade}\] % % % \subsubsection*{Example with radial shading} % Code: % \begin{verbatim} % \[ % \tikzmarkin[outer color=white, inner color=blue!20]{rshade} % x+y=400 % \tikzmarkend{rshade} % \] % \end{verbatim} % Result: % \[\tikzmarkin[outer color=white, inner color=blue!20]{rshade}x+y=400\tikzmarkend{rshade}\] % % \subsection{Avoiding the background color} % \DescribeMacro{nofill}^^A % Using the \smoption{nofill} option allows very simply to not introduce the background color. % When the option is active, you can not change this behaviour inside the document. Another way to remove the background color, is to set the fill color by means of \cs{hfsetfillcolor} to be of the same color of the page. % \subsection{Disable rounded corners} % \DescribeMacro{norndcorners}^^A % To disable the rounded corners, it exists two ways actually. The first one, which is a global approach, is the option \smoption{norndcorners}: as any of the other package options, it should be provided during the package load. % % It exists a second way that disables the rounded corners only locally; this approach needs the \smkey{disable rounded corners} key to be set to \verb|true|. % % For example: % \begin{verbatim} % \[ % \tikzmarkin[disable rounded corners=true]{mark 1} % x+y=400 % \tikzmarkend{mark 1} % \] % \end{verbatim} % The result: % \[\tikzmarkin[disable rounded corners=true]{mark 1}x+y=400\tikzmarkend{mark 1}\] % % \subsection{The \texttt{markings} option}\label{subsec:markings} % \DescribeMacro{markings}^^A % Loading the package with the \smoption{markings} option allows to mark positions on the box delimiting the highlighted area. This can be achieved by setting the key \smkey{mark at}\verb|=| where \verb|=[0,1]|; the positions can be later accessed with the key \smkey{use marker id}\verb|=| where \verb|| is the progressive identifier of the positions previously marked. % % For example: % \tikzset{set fill color=orange!30,set border color=orange} % \[ % \tikzmarkin[show markers,mark at=0,]{marker 1} % x+y=400 % \tikzmarkend{marker 1} % \tikz[remember picture,overlay]{ % \draw[use marker id,blue,xscale=-1](0,0)arc(270:90:1.5mm); % } % \] % is realized by means of: % \begin{verbatim} % \tikzset{set fill color=orange!30,set border color=orange} % \[ % \tikzmarkin[show markers,mark at=0,]{marker 1} % x+y=400 % \tikzmarkend{marker 1} % \tikz[remember picture,overlay]{ % \draw[use marker id,blue,xscale=-1](0,0)arc(270:90:1.5mm); % } % \] % \end{verbatim} % % Actually, it is possible to mark more than one point: % \[ % \tikzmarkin[show markers,mark at=0,mark at=0.55]{marker 2} % x+y=400 % \tikzmarkend{marker 2} % \tikz[remember picture,overlay]\draw[use marker id=1,blue,xscale=-1](0,0)arc(270:90:1.5mm); % \tikz[remember picture,overlay]\draw[use marker id=2,blue](0,0)arc(270:90:1.5mm); % \] % by referring them in the same order in which they have been marked: % \begin{verbatim} % \[ % \tikzmarkin[show markers,mark at=0,mark at=0.55]{marker 2} % x+y=400 % \tikzmarkend{marker 2} % \tikz[remember picture,overlay]{ % \draw[use marker id=1,blue,xscale=-1](0,0)arc(270:90:1.5mm); % } % \tikz[remember picture,overlay]{ % \draw[use marker id=2,blue](0,0)arc(270:90:1.5mm); % } % \] % \end{verbatim} % % The markers can become visible when the \smkey{show markers} key is activated. By default, they are invisible, but during the working process it may be useful to know their location. In addition, the markers can be customized: % \begin{itemize} % \item \packoption{marker size}{1pt}: this key sets the radius of the marker; % \item \packoption{marker color}{blue}: this key sets the color of the marker. % \end{itemize} % % The options necessitates of the \library{decorations.markings} of Ti\textit{k}Z: this library, however, is not always loaded, but just in case the \hftikz\ \smoption{markings} option is active. % % \section{Efficient use of Ti\textit{k}Z styles} % Ti\textit{k}Z are very powerful and their use is recommended also with \hftikz. For example, an intelligent way to proceed if two different highlighting colors have to be used is as follows: %\begin{verbatim} %\tikzset{offset definition/.style={ % above left offset={-0.1,0.6}, % below right offset={0.1,-0.45}, % }, % h1/.style={ % offset definition, % set fill color=green!50!lime!60, % set border color=green!40!black, % }, % h2/.style={ % offset definition, % set fill color=blue!20!cyan!60, % set border color=blue!60!cyan, % } %} %\end{verbatim} %\tikzset{offset definition/.style={ % above left offset={-0.1,0.6}, % below right offset={0.1,-0.45}, % }, % h1/.style={ % offset definition, % set fill color=green!50!lime!60, % set border color=green!40!black, % }, % h2/.style={ % offset definition, % set fill color=blue!20!cyan!60, % set border color=blue!60!cyan, % } %} % Their use in the document is: % \begin{verbatim} % \[\tikzmarkin[h1]{st-a}x + \dfrac{y}{z} = 400\tikzmarkend{st-a}\] % \[\tikzmarkin[h2]{st-b}x + \dfrac{y}{z} = 400\tikzmarkend{st-b}\] % \end{verbatim} % which gives as result: % \[\tikzmarkin[h1]{st-a}x + \dfrac{y}{z} = 400\tikzmarkend{st-a}\] % and % \[\tikzmarkin[h2]{st-b}x + \dfrac{y}{z} = 400\tikzmarkend{st-b}\] % % \StopEventually{\PrintChanges} % % \section{Implementation} % % \iffalse %<*package> % \fi % % \begin{macrocode} \RequirePackage{tikz} \usetikzlibrary{shadings} \RequirePackage{xparse} \RequirePackage{etoolbox} % \end{macrocode} % % This warning is arised after the first compilation run to inform that a second run is necessary for the final result. The code % has been inspired by \href{http://tex.stackexchange.com/a/82072/13304}{this answer on TeX.SX}. % % \begin{macrocode} \AtEndDocument{% \let\oldpgfsyspdfmark\pgfsyspdfmark \def\pgfsyspdfmark#1#2#3{% \expandafter\let\expandafter\tmp\csname pgf@sys@pdf@mark@pos@#1\endcsname \oldpgfsyspdfmark{#1}{#2}{#3}% \expandafter\ifx\csname pgf@sys@pdf@mark@pos@#1\endcsname\tmp\else \let\oldsavepointas\savepointas \def\savepointas##1##2{% \immediate\write\@auxout{hf-TikZ Warning: Mark '##1' changed. Rerun to get mark in right position.}% } \fi }} % \end{macrocode} % % \subsection{Options definition} % This subsection is devoted to define options and default colors. % % \begin{macrocode} %% Colors % Pre-defined colors \definecolor{fancybrown}{RGB}{255,216,197} \definecolor{fancyviolet}{RGB}{197,122,197} \newcommand{\fcol}{fancybrown} \newcommand{\bcol}{fancyviolet} %% Package option \newbool{fill} \booltrue{fill} \DeclareOption{nofill}{\boolfalse{fill}} \DeclareOption{customcolors}{ \def\hfsetfillcolor#1{\renewcommand{\fcol}{#1}} \def\hfsetbordercolor#1{\renewcommand{\bcol}{#1}} \pgfkeys{/tikz/.cd, set fill color/.code={\renewcommand{\fcol}{#1}}, set border color/.code={\renewcommand{\bcol}{#1}} } } \newbool{shade} \boolfalse{shade} \DeclareOption{shade}{\booltrue{shade}} \newbool{beamer} \boolfalse{beamer} \DeclareOption{beamer}{\booltrue{beamer}} \newbool{norndcorners} \boolfalse{norndcorners} \DeclareOption{norndcorners}{\booltrue{norndcorners}} \newbool{markings} \boolfalse{markings} \DeclareOption{markings}{\booltrue{markings}} \ProcessOptions % \end{macrocode} % % It follows the definition of the keys devoted to disable the rounded corners. % % \begin{macrocode} \pgfkeys{/tikz/.cd,% not use rounded corners/.is choice,% not use rounded corners/true/.style={rounded corners=0pt},% not use rounded corners/false/.style={rounded corners},% }% \tikzset{disable rounded corners/.estyle={% not use rounded corners=#1,% },% disable rounded corners/.default=false,% }% % \end{macrocode} % % Offsets keys' definition: for compatibility reasons, the initial values change according to the presence of the \smoption{fill} option. % % \begin{macrocode} \ifbool{fill}{% \pgfkeys{/tikz/.cd,% left offset/.initial=-0.1, right offset/.initial=0.1, above offset/.initial=0.35, below offset/.initial=-0.18, } }{ \pgfkeys{/tikz/.cd,% left offset/.initial=-0.075, right offset/.initial=0.075, above offset/.initial=0.35, below offset/.initial=-0.18, } } \pgfkeys{/tikz/.cd,% left offset/.get=\leftoff, left offset/.store in=\leftoff, right offset/.get=\rightoff, right offset/.store in=\rightoff, above offset/.get=\aboveoff, above offset/.store in=\aboveoff, below offset/.get=\belowoff, below offset/.store in=\belowoff, below right offset/.initial={\rightoff,\belowoff}, below right offset/.get=\belowrightoff, below right offset/.store in=\belowrightoff, above left offset/.initial={\leftoff,\aboveoff}, above left offset/.get=\aboveleftoff, above left offset/.store in=\aboveleftoff, }% % \end{macrocode} % % Keys and style definition of the markings: they are activated when the \smoption{markings} option is present. This is a feature request from Bodo Manthey and the implementation has been inspired by Jake's \href{http://tex.stackexchange.com/a/25940/13304}{answer on TeX.SX}: thanks to both. % % \begin{macrocode} \ifbool{markings}{ \usetikzlibrary{decorations.markings} \newif\ifshowmarkers \pgfkeys{/tikz/show markers/.is if=showmarkers} \pgfkeys{/tikz/show markers=false} \pgfkeys{/tikz/.cd,% marker color/.initial=blue, marker color/.get=\colmarker, marker color/.store in=\colmarker, marker size/.initial=1pt, marker size/.get=\sizemarker, marker size/.store in=\sizemarker, } \tikzset{ mark at/.style={ decoration={ markings, mark= at position #1 with { \coordinate (marker point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt); \coordinate (marker unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt); \coordinate (marker orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1); \ifshowmarkers% conditional to make them appear just when invoked \draw[draw=none,fill=\colmarker,radius=\sizemarker] (0,0) circle ; \else \relax \fi } }, postaction=decorate }, use marker id/.style={ shift=(marker point-#1), x=(marker unit vector-#1), y=(marker orthogonal unit vector-#1) }, use marker id/.default=1, } } % \end{macrocode} % \subsection{General settings} % This subsection is devoted to illustrate the code used for defining the settings used by the highlighting commands. % \begin{macrocode} %% Settings \ifbool{beamer}{%true \newcounter{jumping} \resetcounteronoverlays{jumping} \def\jump@setbb#1#2#3{% \@ifundefined{jump@#1@maxbb}{% \expandafter\gdef\csname jump@#1@maxbb\endcsname{#3}% }{% \csname jump@#1@maxbb\endcsname \pgf@xa=\pgf@x \pgf@ya=\pgf@y #3 \pgfmathsetlength\pgf@x{max(\pgf@x,\pgf@xa)}% \pgfmathsetlength\pgf@y{max(\pgf@y,\pgf@ya)}% \expandafter\xdef\csname jump@#1@maxbb\endcsname{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}% } \@ifundefined{jump@#1@minbb}{% \expandafter\gdef\csname jump@#1@minbb\endcsname{#2}% }{% \csname jump@#1@minbb\endcsname \pgf@xa=\pgf@x \pgf@ya=\pgf@y #2 \pgfmathsetlength\pgf@x{min(\pgf@x,\pgf@xa)}% \pgfmathsetlength\pgf@y{min(\pgf@y,\pgf@ya)}% \expandafter\xdef\csname jump@#1@minbb\endcsname{\noexpand\pgfpoint{\the\pgf@x}{\the\pgf@y}}% } } \tikzset{% remember picture with id/.style={% remember picture, overlay, save picture id=#1, }, save picture id/.code={% \edef\pgf@temp{#1}% \immediate\write\pgfutil@auxout{% \noexpand\savepointas{\pgf@temp}{\pgfpictureid}}% }, if picture id/.code args={#1#2#3}{% \@ifundefined{save@pt@#1}{% \pgfkeysalso{#3}% }{ \pgfkeysalso{#2}% } }, onslide/.code args={<#1>#2}{% \only<#1>{\pgfkeysalso{#2}}% }, alt/.code args={<#1>#2#3}{% \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}}% }, stop jumping/.style={ execute at end picture={% \stepcounter{jumping}% \immediate\write\pgfutil@auxout{% \noexpand\jump@setbb{\the\value{jumping}}{\noexpand\pgfpoint{\the\pgf@picminx}{\the\pgf@picminy}}{\noexpand\pgfpoint{\the\pgf@picmaxx}{\the\pgf@picmaxy}} }, \csname jump@\the\value{jumping}@maxbb\endcsname \path (\the\pgf@x,\the\pgf@y); \csname jump@\the\value{jumping}@minbb\endcsname \path (\the\pgf@x,\the\pgf@y); }, } } }{% false \tikzset{% remember picture with id/.style={% remember picture, overlay, save picture id=#1, }, save picture id/.code={% \edef\pgf@temp{#1}% \immediate\write\pgfutil@auxout{% \noexpand\savepointas{\pgf@temp}{\pgfpictureid}}% }, if picture id/.code args={#1#2#3}{% \@ifundefined{save@pt@#1}{% \pgfkeysalso{#3}% }{ \pgfkeysalso{#2}% } } } } \def\savepointas#1#2{% \expandafter\gdef\csname save@pt@#1\endcsname{#2}% } \def\tmk@labeldef#1,#2\@nil{% \def\tmk@label{#1}% \def\tmk@def{#2}% } \tikzdeclarecoordinatesystem{pic}{% \pgfutil@in@,{#1}% \ifpgfutil@in@% \tmk@labeldef#1\@nil \else \tmk@labeldef#1,(0pt,0pt)\@nil \fi \@ifundefined{save@pt@\tmk@label}{% \tikz@scan@one@point\pgfutil@firstofone\tmk@def }{% \pgfsys@getposition{\csname save@pt@\tmk@label\endcsname}\save@orig@pic% \pgfsys@getposition{\pgfpictureid}\save@this@pic% \pgf@process{\pgfpointorigin\save@this@pic}% \pgf@xa=\pgf@x \pgf@ya=\pgf@y \pgf@process{\pgfpointorigin\save@orig@pic}% \advance\pgf@x by -\pgf@xa \advance\pgf@y by -\pgf@ya }% } % \end{macrocode} % \subsection{The highlighting commands} % In this subsection the definitions of the highlighing commands are shown when the \texttt{beamer} mode is active and when it is not. Thanks to \textsf{etoolbox} it is possible to perform a check on the active options. Then the commands are declared. % \begin{macrocode} \ifbool{norndcorners}{%true-norndcorners \ifbool{beamer}{%true-beamer \ifbool{fill}{%true-fill \ifbool{shade}{%true-shade \NewDocumentCommand{\tikzmarkin}{r<> o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#2}{%true-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,fill=\fcol,draw=\bcol] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;} }{%false-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,fill=\fcol,draw=\bcol,#2] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;}} } }{%false-shade \NewDocumentCommand{\tikzmarkin}{r<> o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#2}{%true-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,fill=\fcol,draw=\bcol] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;} }{%false-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,fill=\fcol,draw=\bcol,#2] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;}} } } }{%false-fill \NewDocumentCommand{\tikzmarkin}{r<> o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#2}{%true-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,draw=\bcol] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;} }{%false-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,draw=\bcol,#2] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;}} } } }{%false-beamer \ifbool{fill}{%true-fill \ifbool{shade}{%true-shade \NewDocumentCommand{\tikzmarkin}{o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#1}{%true-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,fill=\fcol,draw=\bcol] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ; }{%false-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,fill=\fcol,draw=\bcol,#1] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ;}} }{%false-shade \NewDocumentCommand{\tikzmarkin}{o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#1}{%true-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,fill=\fcol,draw=\bcol] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ; }{%false-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,fill=\fcol,draw=\bcol,#1] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ;}} } }{%false-fill \NewDocumentCommand{\tikzmarkin}{o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#1}{%true-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,draw=\bcol] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ; }{%false-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,draw=\bcol,#1] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ;}} % \NewDocumentCommand{\tikzmarkin}{m D(){0.075,-0.18} D(){-0.075,0.35}}{% % \tikz[remember picture,overlay] % \draw[line width=1pt,rectangle,draw=\bcol] % (pic cs:#1) ++(#2) rectangle (#3) node [anchor=base] (#1){} % ;} } } }{%false-norndcorners \ifbool{beamer}{%true-beamer \ifbool{fill}{%true-fill \ifbool{shade}{%true-shade \NewDocumentCommand{\tikzmarkin}{r<> o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#2}{%true-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;} }{%false-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol,#2] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;}} } }{%false-shade \NewDocumentCommand{\tikzmarkin}{r<> o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#2}{%true-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;} }{%false-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol,#2] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;}} } } }{%false-fill \NewDocumentCommand{\tikzmarkin}{r<> o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#2}{%true-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,draw=\bcol] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;} }{%false-val \only<#1>{\tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,draw=\bcol,#2] (pic cs:#3) ++(#4) rectangle (#5) node [anchor=base] (#3){} ;}} } } }{%false-beamer \ifbool{fill}{%true-fill \ifbool{shade}{%true-shade \NewDocumentCommand{\tikzmarkin}{o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#1}{%true-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ; }{%false-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol,#1] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ;}} }{%false-shade \NewDocumentCommand{\tikzmarkin}{o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#1}{%true-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ; }{%false-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,fill=\fcol,draw=\bcol,#1] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ;}} } }{%false-fill \NewDocumentCommand{\tikzmarkin}{o m D(){\belowrightoff} D(){\aboveleftoff}}{% \IfNoValueTF{#1}{%true-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,draw=\bcol] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ; }{%false-val \tikz[remember picture,overlay] \draw[line width=1pt,rectangle,disable rounded corners,draw=\bcol,#1] (pic cs:#2) ++(#3) rectangle (#4) node [anchor=base] (#2){} ;}} } } } \newcommand\tikzmarkend[2][]{% \tikz[remember picture with id=#2] #1;} % \end{macrocode} % \iffalse % % \fi % % \Finale \endinput