Skip to content

LaTeX export fails to correctly escape newlines in titles #599

@JasonGross

Description

@JasonGross

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions