
Al intentar escribir algunos comandos para simplificar la generación de líneas de tiempo con tikz, me encontré con este error:
MWE:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfcalendar}
\begin{document}
\newcount\StartTime
\newcount\EndTime
\begin{tikzpicture}
\pgfcalendardatetojulian{2021-01-01}{\StartTime}
\pgfcalendardatetojulian{2022-01-01}{\EndTime}
\typeout{\the\StartTime}
\draw let
\n{length} = (\the\StartTime-\the\EndTime),
in
(0,0) -- (\n{length},0);
\end{tikzpicture}
\end{document}
Me pone al ejecutar este resultado:
2459216
/media/daten/coding/01_manuals/tex/testing/chrono/mwe.tex:17: Use of \tikz@cc@stop@let doesn't match its definition.
<recently read> \the
l.17 \n{length} = (\the
\StartTime-\the\EndTime),
Veo que tengo problemas para obtener el valor de los contadores allí. Como soy un novato con respecto a la expansión en LaTeX, lamentablemente no puedo solucionar este problema por mi cuenta (y la investigación en Internet no resultó en nada útil).
¿Alguien puede ayudarme a llevar los contadores tex a tikz?
Respuesta1
La \n{<number register>}
sintaxis tiene de
\n{<number register>} = {<pgfmath expression>}
Por lo tanto, debería ser \n{length} = {\the\StartTime-\the\EndTime}
(llaves, no paréntesis).
Sin embargo, \n{length} = {\the\StartTime-\the\EndTime}
generará errores de "Dimensión demasiado grande", ya que ambos \StartTime
y \EndTime
son números enteros demasiado grandes para que las dimensiones se mantengan (en pt
).
Solución alterna:
Calcule la diferencia entre \StartTime
y \EndTime
antes pgfmath
de analizar la expresión matemática. Esto puede tener lugar antes \draw
(con la ayuda de otro recuento) o in situ de forma ampliable.
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfcalendar}
\begin{document}
\newcount\StartTime
\newcount\EndTime
\begin{tikzpicture}
\pgfcalendardatetojulian{2021-01-01}{\StartTime}
\pgfcalendardatetojulian{2022-01-01}{\EndTime}
\typeout{\the\StartTime}
\draw let
\n{length} = {\the\numexpr\StartTime-\EndTime pt},
in
% \n{length} is -365pt
(0,0) -- (\n{length},0);
\end{tikzpicture}
\end{document}