%!TEX pdflatex
\documentclass[a4paper,french,11pt]{article}
\usepackage[margin=1.25cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,bending}
\pgfdeclarearrow{
name=plume,
parameters= {\the\pgfarrowlength},
setup code={
\pgfarrowssettipend{0pt}
\pgfarrowssetlineend{-\pgfarrowlength}
\pgfarrowlinewidth=\pgflinewidth
\pgfarrowssavethe\pgfarrowlength
},
drawing code={
\pgfpathmoveto{\pgfpoint{-\pgfarrowlength}{0.5\pgflinewidth}}
\pgfpathcurveto{\pgfpoint{-0.75\pgfarrowlength}{0.6\pgflinewidth}}{%
\pgfpoint{-0.01\pgfarrowlength}{0.6\pgflinewidth}}{%
\pgfpoint{0pt}{0pt}}
\pgfpathcurveto{\pgfpoint{-0.01\pgfarrowlength}{-0.5\pgflinewidth}}{%
\pgfpoint{-0.2\pgfarrowlength}{-(1+0.3*rnd)*\pgflinewidth}}{%
\pgfpoint{-0.3\pgfarrowlength}{-0.8*(1+0.3*rnd)*\pgflinewidth}}
\pgfpathcurveto{\pgfpoint{-0.4\pgfarrowlength}{-0.6*(1+0.3*rnd)*\pgflinewidth}}{%
\pgfpoint{-0.6\pgfarrowlength}{-0.3*(1+0.3*rnd)*\pgflinewidth}}{%
\pgfpoint{-1\pgfarrowlength}{-0.5\pgflinewidth}}
\pgfusepathqfill
},
defaults={length=8pt}
}
\usepackage{codehigh}
\setlength\parindent{0pt}
\usepackage{babel}
\makeatletter
\newcommand\calcwidthnodetikz[2]{%
\pgfpointdiff{\pgfpointanchor{#1}{east}}{\pgfpointanchor{#1}{west}}%
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
% to convert from pt to cm
\pgfmathparse{veclen(\pgf@xa,\pgf@ya)/28.45274}%
\global\let#2\pgfmathresult%
}
\newcommand\calcheightnodetikz[2]{%
\pgfpointdiff{\pgfpointanchor{#1}{south}}{\pgfpointanchor{#1}{north}}%
\pgf@xa=\pgf@x
\pgf@ya=\pgf@y
% to convert from pt to cm
\pgfmathparse{veclen(\pgf@xa,\pgf@ya)/28.45274}%
\global\let#2\pgfmathresult%
}
\makeatother
\NewDocumentCommand\tkzentoure{ O{1.25pt} m m O{AAAAZ} }{%
%#1=width
%#2=color
%#3=text
%#4=node
{\tikz[remember picture,baseline=(#4.base)]%
{\node[shape=rectangle,inner sep=0pt](#4){#3};}%
}%
\begin{tikzpicture}[remember picture,overlay]
\calcwidthnodetikz{#4}{\mytmpwidthnode}%
\xdef\offsettmpdecoh{\fpeval{-0.15*\mytmpwidthnode}}%
\xdef\offsettmpdecohb{\fpeval{0.25*\mytmpwidthnode}}%
\path[draw,line width=#1,#2,{plume[bend]}-{plume[bend]}] plot[smooth] coordinates {([yshift=1.5mm]#4.north) ([xshift=-0.25mm,yshift=0.1mm]#4.north west) ([yshift=-0.2mm]#4.south west) ([xshift=-\offsettmpdecoh cm,yshift=-1mm]#4.south) ([yshift=-0.15mm]#4.south east) ([xshift=0.25mm,yshift=0.2mm]#4.north east) ([xshift=\offsettmpdecohb cm,yshift=1mm]#4.north) ([xshift=\offsettmpdecoh cm,yshift=-0.1mm]#4.north)};%
\end{tikzpicture}%
}
\newlength\tkzheightsoulign
\NewDocumentCommand\tkzsouligne{ O{1.25pt} D(){1cm} m m O{BBBBZ} }{%
%#1=width
%#2=height
%#3=color
%#4=text
%#5=node
{\tikz[remember picture,baseline=(#5.base)]%
{\node[shape=rectangle,inner sep=0pt](#5){#4};}%
}%
\begin{tikzpicture}[remember picture,overlay]
\setlength\tkzheightsoulign{#2}%
\calcwidthnodetikz{#5}{\mytmpwidthnode}%
\xdef\offsettmpdecoha{\fpeval{0.25*\mytmpwidthnode}}%
\xdef\offsettmpdecohb{\fpeval{0.175*\mytmpwidthnode}}%
\xdef\offsettmpdecohc{\fpeval{0.1*\mytmpwidthnode}}%
\xdef\offsettmpdecohd{\fpeval{0.005*\mytmpwidthnode}}%
\path[draw,line width=#1,#3,{plume[bend]}-{plume[bend]}] plot[smooth] coordinates {([yshift=-0.5*#1]#5.south west) ([yshift=-#1]#5.south east) ([xshift=-\offsettmpdecoha cm,yshift=-0.15\tkzheightsoulign]#5.south) ([xshift=\offsettmpdecohb cm,yshift=-0.275\tkzheightsoulign]#5.south) ([xshift=-\offsettmpdecohc cm,yshift=-0.4\tkzheightsoulign]#5.south) ([yshift=-0.525\tkzheightsoulign]#5.south) } to ([xshift=\offsettmpdecohd cm,yshift=-\tkzheightsoulign]#5.south) ;
\end{tikzpicture}%
}
\begin{document}
\section*{Décoration 'entourage'}
\begin{demohigh}[language=latex/latex2]
\tkzentoure{red}{Ceci est un texte et on} essaye de voir ce que ça \tkzentoure{blue}{donne} en entourant certaines portions\ldots
\end{demohigh}
\begin{demohigh}[language=latex/latex2]
On peut essayer avec une formule :%
\tkzentoure{teal}{$I= \displaystyle\int_{a}^{b} f(x) \textrm{d}x = F(b)-F(a)$}.
\end{demohigh}
\section*{Décoration 'soulignage'}
\begin{demohigh}[language=latex/latex2]
\tkzsouligne{orange}{Essai de soulignage personnalisé} pour voir
\end{demohigh}
\vspace*{1cm}
\begin{demohigh}[language=latex/latex2]
\tkzsouligne[0.75mm](2cm){violet}{Essai de soulignage personnalisé} pour voir
\end{demohigh}
\end{document}