6

Is there a way (with tikz) to get an effect like shown in the following image?

enter image description here

I.e. what command \inserteffect would yield that effect instead of just inserting in brackets as is the case for the following MWE (pdflatex):

\documentclass{article}
\newcommand{\inserteffect}[1]{(#1)}
\begin{document}
Here some \inserteffect{very nice} text.
\end{document}
Ignasi
  • 136,588

1 Answers1

11

Something like this? This does use TikZ, even though that is really overkill.

\documentclass[welsh]{article}
\usepackage{tikz,babel}
\usetikzlibrary{calc,tikzmark}
\begin{document}

  Yn y fan hon, mae\tikzmark{a} \tikzmark{b}geiriau.

  \hskip 5em\tikzmark{c}testun neis iawn\tikzmark{d}

  \begin{tikzpicture}[overlay, remember picture]
    \draw ([xshift=-.25em]{pic cs:c}) -- ++(0,.25em) [out=90, in=-95] to ([yshift=.25em]$({pic cs:a})!1/2!({pic cs:b})$) [out=-85, in=90] to ([yshift=.25em, xshift=.25em]{pic cs:d}) -- ++(0,-.25em);
  \end{tikzpicture}
\end{document}

geiriau

EDIT

Here's a version which works with a single command. However, you need to ensure that sufficient vertical space is left for the text to fit.

The command takes 2 arguments. The first is a unique name for that point on the page. The second is the text.

\documentclass[welsh]{article}
\usepackage{tikz,babel}
\usetikzlibrary{calc,tikzmark}
\newcommand\neis[2]{%
  \tikzmark{#1}%
  \tikz[remember picture,overlay]{%
    \node (#1-1) [inner ysep=.1em] at ([yshift=-1em]{pic cs:#1}) {#2};
    \draw (#1-1.south west) -- ++(0,.25em) [out=90, in=-95] to ([yshift=.25em]{pic cs:#1}) [out=-85, in=90] to ([yshift=.25em]#1-1.south east) -- ++(0,-.25em);
  }%
}
\begin{document}

  Yn y fan hon, mae \neis{a}{testun neis iawn} geiriau.\bigskip

  Dyma'r \neis{b}{geiriau bendigedig} testun arall.
\end{document}

geiriau bendigedig

EDIT 2

If you really want to squeeze it between lines of text, you can. However, I don't see much point in doing this as both the text and the addition will tend quickly towards the illegible.

But, heck, this site is about the technical implementation of ideas in TikZ, however batty they may be.

\documentclass[welsh]{article}
\usepackage{tikz,babel}
\usetikzlibrary{calc,tikzmark}
\newcommand\neis[2]{%
  \tikzmark{#1}%
  \tikz[remember picture,overlay]{%
    \node (#1-1) [font=\tiny, inner xsep=.1em, inner ysep=.05em] at ([yshift=-.35em]{pic cs:#1}) {#2};
    \draw [thin] (#1-1.south west) -- ++(0,.075em) [out=90, in=-95] to ([yshift=.25em]{pic cs:#1}) [out=-85, in=90] to ([yshift=.075em]#1-1.south east) -- ++(0,-.075em);
  }%
}
\begin{document}

  Yn y fan hon, mae \neis{a}{testun neis iawn} geiriau.

  Dyma'r \neis{b}{geiriau bendigedig} testun arall.

  Y mae llawer o eiriau mewn ieithoedd --- hyd yn oed yn un ohonynt.
\end{document}

batty

EDIT 3

Here's a version which assumes double-spacing and uses \footnotesize for the inserted text. Although still somewhat squeezed, around about this seems to me a reasonable compromise.

\documentclass[welsh]{article}
\usepackage{tikz,babel,setspace}
\usetikzlibrary{calc,tikzmark}
\newcommand\neis[2]{%
  \tikzmark{#1}%
  \tikz[remember picture,overlay]{%
    \node (#1-1) [inner xsep=.2em, inner ysep=.05em, font=\footnotesize] at ([yshift=-.65em]{pic cs:#1}) {#2};
    \draw [thin] (#1-1.south west) -- ++(0,.25em) [out=90, in=-95] to ([yshift=.25em]{pic cs:#1}) [out=-85, in=90] to ([yshift=.25em]#1-1.south east) -- ++(0,-.25em);
  }%
}
\begin{document}
  \doublespacing

  Yn y fan hon, mae \neis{a}{testun neis iawn} geiriau.

  Dyma'r \neis{b}{geiriau bendigedig} testun arall.

  Y mae llawer o eiriau mewn ieithoedd --- hyd yn oed yn un ohonynt.
\end{document}

saner

cfr
  • 198,882
  • Nice! Can this be transformed into one command one just places in the text like shonw in the MWE? – aguestforfun Jul 05 '15 at 20:53
  • @aguestforfun What about the text or whatever which is otherwise below the line? Should this take space or not? – cfr Jul 05 '15 at 20:56
  • Ideally 'testun neis iawn' should squeeze between the surrounding lines of text. – aguestforfun Jul 05 '15 at 20:59
  • @aguestforfun See edit. You need to allow space for it, though. I'm not sure how you could make it look like your target image and fit between the lines of text since the image you showed has the text -to-be-squeezed in the same size as the text on the line. If you double space or something, of course that would work and you would need to manually ensure sufficient space in particular instances. – cfr Jul 05 '15 at 21:37
  • @aguestforfun See also edit 2. – cfr Jul 05 '15 at 21:40
  • wow, thank you very much! I only removed the xshift and added some custom decoration. Very nice. I agree, and indeed use double spacing. – aguestforfun Jul 05 '15 at 21:48
  • @aguestforfun You're welcome. I meant, of course, that you would not need to specify extra space in that case. If you use double spacing, I can see it working. \small is probably a good size for the text in that case? – cfr Jul 05 '15 at 22:06
  • @aguestforfun Oh, and, yes, there was a spurious xshift which I removed above when I realised it. – cfr Jul 05 '15 at 22:08
  • @aguestforfun OK. Final edit (I hope!). – cfr Jul 05 '15 at 22:15