1

Today I write the following code snippet in a latex file and what I want to achieve works well :

\draw [dotted] (\ordinateOnTimeAxis{-1500}, 2 * \laneHeight) -- (\ordinateOnTimeAxis{-1500}, 2 * \laneHeight - 20);
\draw[xshift=\ordinateOnTimeAxis{-1500}, yshift=2 * \laneHeight -20]
node[draw, dotted, anchor=north west, text width=\textWidth, align=justify, inner sep=10]
{
    \textbf{Lorem ipsum}\\ et caetera...
};

where ordinateOnTimeAxis is a Lua function.
The above places a box at the right place in a TikZ diagram with a descriptive text inside it.

You notice that is a lot of repeated text here :

  • 1500 appears several times
  • 2 as well
  • ordinateOnTimeAxis as well

What I would like to do is to replace all that text by something simpler where only variables are kept like :

\dateDescription{-1500}{2}{north west}{
    \textbf{Lorem ipsum}\\ et caetera...
}

I want to write Lua that writes LaTeX that references Lua functions.
Is this back and forth achievable ?
I'd rather stick to Lua if it is possible since it is simpler for people that are not familiar with LaTeX complexities.
If not, what could be an alternative?

All my attempts so far did fail since I am not at all confident with LaTeX.
Thank you for your interest in my question.

1 Answer 1

2

It can be done in Lua (hard to say why your attempts failed if you don't show what you tried) but for such simple text replacements it's easier to just do it in TeX:

\newcommand \dateDescription[4] {% 4 arguments, can be used as #1, #2, #3 and #4
  \draw [dotted] (\ordinateOnTimeAxis{#1}, #2 * \laneHeight) -- (\ordinateOnTimeAxis{#1}, #2 * \laneHeight - 20);
  \draw[xshift=\ordinateOnTimeAxis{#1}, yshift=#2 * \laneHeight -20]
node[draw, dotted, anchor=#3, text width=\textWidth, align=justify, inner sep=10]
  {#4};
}
1
  • Thank you ! It works perfectly. Sep 14, 2021 at 12:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .