\documentclass{article}
\usepackage{tikz, amsmath}
\newcommand{\highlight}[2][black]{\tikz[baseline, anchor=base]{\node[inner sep=2mm](A){$#2$};
\draw[#1] (A.north east)--(A.south east)--(A.south west);
\draw[#1] ([shift={(.1,.5)}]A.south east)--([shift={(-.5,-.1)}]A.south east);
\draw[#1] ([shift={(.1,.3)}]A.south east)--([shift={(-.3,-.1)}]A.south east);
}}
\begin{document}
\begin{center}
\highlight{a_{\rho}=\dfrac{V^2}{\rho}}
\end{center}
\end{document}
2 Answers
This uses tikzmark
and requires naming a tikzmarknode
at the beginning and another at the end. After the align
environment, call the \highlight
macro with the nodes you named.
You must compile twice.
\documentclass{article}
\usepackage{tikz, amsmath}
\usetikzlibrary{tikzmark}
\newcommand{\highlight}[3][orange!70]{\tikz[remember picture, overlay]{
\draw[very thick, shorten >=-3mm, #1] ([shift={(.2,.1)}]#3.north east)--([shift={(.2,-.2)}]#3.south east)--([shift={(.2,-.2)}]#3.south east-|#2.west);
\draw[thick, #1] ([shift={(.3,.3)}]#3.south east)--([shift={(-.3,-.3)}]#3.south east);
\draw[#1] ([shift={(.3,.1)}]#3.south east)--([shift={(-.1,-.3)}]#3.south east);
}}
\begin{document}
\begin{align*}
x&=1\\
y&=2\\
\tikzmarknode{A}{a_{\rho}}&=\tikzmarknode{B}{\dfrac{V^2}{\rho}}
\end{align*}
\highlight{A}{B}
\end{document
Code
\documentclass{article}
\usepackage{tikz, mathtools}
\pgfqkeys{/tikzHighlight}{
.code=\pgfqkeys{/tikzHighlight}{#1},
.unknown/.code=\pgfkeyssetevalue{/tikzHighlight/color}{\pgfkeyscurrentname},
color/.initial=black, text/.initial=black,
node/.style={
text=\pgfkeysvalueof{/tikzHighlight/text},
anchor=base,overlay=false,inner sep=\fboxsep+.5\fboxrule, outer sep=+0pt,
append after command={(\tikzlastnode.north east)|-(\tikzlastnode.south west)
{[shift=(\tikzlastnode.south east),rotate=45]
(-2mm,1mm) edge[thin] (2mm,1mm) (-3mm,2mm) edge (3mm,2mm)}}
},
path/.style={
overlay,thick,line cap=round,draw=\pgfkeysvalueof{/tikzHighlight/color}},
}
\newcommand*\highlight[1][]{%
\gdef\tikzHighlightOptions{#1}%
\tikzHighlightBoxedInt}
\newcommand*\tikzHighlightBoxed[1]{%
\tikz[baseline,/tikzHighlight/.expand once=\tikzHighlightOptions]
\draw[/tikzHighlight/path]node[/tikzHighlight/node]{#1};}
\MakeAboxedCommand\tikzHighlightBoxedInt\tikzHighlightBoxed
\begin{document}
\begin{align}
\highlight {a_{\rho} &= \frac{V^2}{\rho}} \\
\highlight[orange!70] {\frac{V^2}{\rho} &= a_{\rho}} \\
\highlight[path/.append style={rounded corners=2pt}]{E &= mc^2}
\end{align}
\end{document}
Output
-
Your tikz answers always are elite and highly technical. If you don't mind, may I cite here an unanswered question of mine? I can delete this comment if you don't appreciate such a request.– DiaaOct 7, 2022 at 23:23
-
1@Diaa Sure, maybe I can take a look at it. But I doubt I've got an answer nobody else could have thought of. Oct 7, 2022 at 23:31
-
Many thanks for your consideration. You can have a look at it here tex.stackexchange.com/q/622325/2288. Thanks again!– DiaaOct 7, 2022 at 23:36