tikzplotlib icon indicating copy to clipboard operation
tikzplotlib copied to clipboard

LaTeX export fails to correctly escape newlines in titles

Open JasonGross opened this issue 1 year ago • 0 comments
trafficstars

Python code on colab generated by ChatGPT

import matplotlib.pyplot as plt
import tikzplotlib

# Create a simple plot
plt.figure()
plt.plot([0, 1, 2], [0, 1, 0])
plt.title("Title with Newline\nCharacter")

# Save the plot using tikzplotlib
tikz_code = tikzplotlib.get_tikz_code()

# Print the generated TikZ/PGFPlots code
print(tikz_code)

TeX:

% This file was created with tikzplotlib v0.10.1.
\begin{tikzpicture}

\definecolor{darkgray176}{RGB}{176,176,176}
\definecolor{steelblue31119180}{RGB}{31,119,180}

\begin{axis}[
tick align=outside,
tick pos=left,
title={Title with Newline
Character},
x grid style={darkgray176},
xmin=-0.1, xmax=2.1,
xtick style={color=black},
y grid style={darkgray176},
ymin=-0.05, ymax=1.05,
ytick style={color=black}
]
\addplot [semithick, steelblue31119180]
table {%
0 0
1 1
2 0
};
\end{axis}

\end{tikzpicture}

Expected TeX has Title with Newline \\ Character instead of

Title with Newline
Character

JasonGross avatar Apr 02 '24 21:04 JasonGross