-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Strange behavior of TikZ #945
Comments
Seems to be a problem in ghostscript; the pieces appear to work... not sure how to go about fixing. What do you not like about svg; it works pretty good here? |
The example above is just a toy example; I usually write more complex TikZ stuff and LaTeXML crashes 99% of the times, even without additional TikZ external libraries; that's why I typically use Recently, I was experimenting with the following trick, related to #902 (the following \RequirePackage{latexml}
\documentclass{book}
\usepackage{graphicx}
\usepackage{xcolor}
\definecolor{MAT-Navy-Blue}{rgb}{0.000,0.447,0.741} % Navy Blue (Blue)
\definecolor{MAT-Chocolate}{rgb}{0.850,0.325,0.098} % Chocolate (Brown)
\definecolor{MAT-Cornflower-Blue}{rgb}{0.301,0.745,0.933} % Cornflower Blue (Blue)
\iflatexml
%\DeclareGraphicsExtensions{%
% .svg,.SVG,%
% .png,.PNG,%
% .pdf,.PDF,%
% .eps,.EPS,%
% .jpg,.mps,.jpeg,.jbig2,.jb2,.JPG,.JPEG,.JBIG2,.JB2}
\else
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize
\tikzsetfigurename{TikZFigure-}
\fi
\newcounter{tikzpicturecounter}
\newcommand{\includetikzexternalized}{
\includegraphics[scale=1.5]{TikZFigure-\thetikzpicturecounter}
\stepcounter{tikzpicturecounter}
}
\begin{document}
\iflatexml
\includetikzexternalized
\else
\begin{tikzpicture}[>=latex, scale=1.0, transform shape]
\colorlet{TextColor}{.}
\def\a{1.8}
\def\XLength{5}
\def\YLength{4}
% Fill the MUC
\fill[color=MAT-Cornflower-Blue,opacity=0.8] (0,0) -- (0,1*\a) -- (4*\a,1*\a) -- (4*\a,0) -- cycle;
% Fill the plaquette with the explicit phase
\fill[color=MAT-Chocolate,opacity=0.8] (2*\a,2*\a) -- (3*\a,2*\a) -- (3*\a,3*\a) -- (2*\a,3*\a) -- cycle;
% Draw vertical dashed lines & ticks
\foreach \xpos in {0,...,\XLength}
{
\pgfmathsetmacro{\XLabel}{int(\xpos+1)}
\draw[dashed,color=black!40!white,text=TextColor]
({\xpos*\a},{-0.5*\a}) -- ({\xpos*\a},{(\YLength+0.5)*\a});
\draw ({\xpos*\a},{-1.05*\a}) node[below] {$\XLabel$} -- ({\xpos*\a},{-0.95*\a});
}
% Draw horizontal dashed lines & ticks
\foreach \ypos in {0,...,\YLength}
{
\pgfmathsetmacro{\YLabel}{int(\ypos+1)}
\draw[dashed,color=black!40!white,text=TextColor]
({-0.5*\a},{\ypos*\a}) -- ({(\XLength+0.5)*\a},{\ypos*\a});
\draw ({-1.05*\a},{\ypos*\a}) node[left] {$\YLabel$} -- ({-0.95*\a},{\ypos*\a});
}
% Draw the lattice sites
\foreach \xpos in {0,...,\XLength}
{
\foreach \ypos in {0,...,\YLength}
{
\draw ({\xpos*\a},{\ypos*\a}) node[circle,fill,color=MAT-Navy-Blue] {};
}
}
% Draw some hopping phases
\draw[->] (-0.15*\a,0.05*\a) to[bend left] node[midway,left] {$e^{i2\pi\vartheta}$} (-0.15*\a,0.95*\a);
\draw[->] (+0.85*\a,0.05*\a) to[bend left] node[midway,left] {$e^{i4\pi\vartheta}$} (+0.85*\a,0.95*\a);
\draw[->] (+1.85*\a,0.05*\a) to[bend left] node[midway,left] {$e^{i6\pi\vartheta}$} (+1.85*\a,0.95*\a);
% Draw the plaquette phase
\draw[->] (2.1*\a,2*\a) to node[midway,below] {$0$} (2.9*\a,2*\a);
\draw[->] (3*\a,2.1*\a) to node[midway,below,sloped] {$8\pi\vartheta$} (3*\a,2.9*\a);
\draw[->] (2.9*\a,3*\a) to node[midway,above] {$0$} (2.1*\a,3*\a);
\draw[->] (2*\a,2.9*\a) to node[midway,below,sloped] {$-6\pi\vartheta$} (2*\a,2.1*\a);
\draw (2.5*\a,2.5*\a) node {$2\pi\vartheta$};
% Draw units and axes
\draw[<->] (\a,-0.35*\a) -- (2*\a,-0.35*\a) node[midway,above] {$a$};
\draw[->] (-\a,-\a) -- ({(\XLength+1)*\a},-\a) node[below] {$m$};
\draw[->] (-\a,-\a) -- (-\a,{(\YLength+1)*\a}) node[left] {$n$};
\end{tikzpicture}
\fi
\end{document} Then, my workflow would be: pdflatex -shell-escape -interaction=nonstopmode MWE.tex
for file in TikZFigure-*; do pdf2svg $file ${file%.pdf}.svg; done
latexml MWE.tex --verbose --inputencoding=utf8 --destination=MWE.xml
latexmlpost MWE.xml --verbose --novalidate --format=html5 --graphicimages --graphicsmap=svg --destination=MWE.html In this way:
This is so far, to me, the only solution that generates good SVG's and doesn't imply endless LaTeXML failures because of my TikZ-filled documents; if you just feed the above example to LaTeXML without all of this gimmick, it goes crazy! 😅🤣 This isn't to say that LaTeXML should have a full support for TikZ, and I don't absolutely expect that as a user; but I think that at this stage the SVG feature is not yet fit for more complex drawings or responsive scaling. |
Hi @matteosecli , We didn't work on this issue explicitly I think, but several tikz-related PRs have landed in the latexml master since the issue was opened. Today, using the latest latexml master and texlive 2019, the first minimal example with which you opened the issue now converts error-free and renders in HTML as: Could you double-check if this advances sufficiently to get this issue closed, or if you would point our attention to something else? Thanks! |
Hi @dginev, sorry for the late reply but I somehow missed the notification email. I'll give it a try as soon as I can and close the issue if the problems are solved! 🙂 |
Hi again @dginev, I've made some tests. Apart from the true pain of making LaTeXML + ImageMagick + Image::Magick work all together on MacOS (HomeBrew's LaTeXML is truly broken, but they are not willing to fix it), I can confirm that the first MWE works as intended. I'm on TeXLive 2017. I've also been able to convert the second, more complex MWE2 that I've sent, by deactivating all the LaTeXML-specific fiddling so that it was back to a regular LaTeX + TikZ file. Just to be clear, this is what the document looks like: \documentclass{book}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{xcolor}
\definecolor{MAT-Navy-Blue}{rgb}{0.000,0.447,0.741} % Navy Blue (Blue)
\definecolor{MAT-Chocolate}{rgb}{0.850,0.325,0.098} % Chocolate (Brown)
\definecolor{MAT-Cornflower-Blue}{rgb}{0.301,0.745,0.933} % Cornflower Blue (Blue)
\begin{document}
\begin{tikzpicture}[>=latex, scale=1.0, transform shape]
\colorlet{TextColor}{.}
\def\a{1.8}
\def\XLength{5}
\def\YLength{4}
% Fill the MUC
\fill[color=MAT-Cornflower-Blue,opacity=0.8] (0,0) -- (0,1*\a) -- (4*\a,1*\a) -- (4*\a,0) -- cycle;
% Fill the plaquette with the explicit phase
\fill[color=MAT-Chocolate,opacity=0.8] (2*\a,2*\a) -- (3*\a,2*\a) -- (3*\a,3*\a) -- (2*\a,3*\a) -- cycle;
% Draw vertical dashed lines & ticks
\foreach \xpos in {0,...,\XLength}
{
\pgfmathsetmacro{\XLabel}{int(\xpos+1)}
\draw[dashed,color=black!40!white,text=TextColor]
({\xpos*\a},{-0.5*\a}) -- ({\xpos*\a},{(\YLength+0.5)*\a});
\draw ({\xpos*\a},{-1.05*\a}) node[below] {$\XLabel$} -- ({\xpos*\a},{-0.95*\a});
}
% Draw horizontal dashed lines & ticks
\foreach \ypos in {0,...,\YLength}
{
\pgfmathsetmacro{\YLabel}{int(\ypos+1)}
\draw[dashed,color=black!40!white,text=TextColor]
({-0.5*\a},{\ypos*\a}) -- ({(\XLength+0.5)*\a},{\ypos*\a});
\draw ({-1.05*\a},{\ypos*\a}) node[left] {$\YLabel$} -- ({-0.95*\a},{\ypos*\a});
}
% Draw the lattice sites
\foreach \xpos in {0,...,\XLength}
{
\foreach \ypos in {0,...,\YLength}
{
\draw ({\xpos*\a},{\ypos*\a}) node[circle,fill,color=MAT-Navy-Blue] {};
}
}
% Draw some hopping phases
\draw[->] (-0.15*\a,0.05*\a) to[bend left] node[midway,left] {$e^{i2\pi\vartheta}$} (-0.15*\a,0.95*\a);
\draw[->] (+0.85*\a,0.05*\a) to[bend left] node[midway,left] {$e^{i4\pi\vartheta}$} (+0.85*\a,0.95*\a);
\draw[->] (+1.85*\a,0.05*\a) to[bend left] node[midway,left] {$e^{i6\pi\vartheta}$} (+1.85*\a,0.95*\a);
% Draw the plaquette phase
\draw[->] (2.1*\a,2*\a) to node[midway,below] {$0$} (2.9*\a,2*\a);
\draw[->] (3*\a,2.1*\a) to node[midway,below,sloped] {$8\pi\vartheta$} (3*\a,2.9*\a);
\draw[->] (2.9*\a,3*\a) to node[midway,above] {$0$} (2.1*\a,3*\a);
\draw[->] (2*\a,2.9*\a) to node[midway,below,sloped] {$-6\pi\vartheta$} (2*\a,2.1*\a);
\draw (2.5*\a,2.5*\a) node {$2\pi\vartheta$};
% Draw units and axes
\draw[<->] (\a,-0.35*\a) -- (2*\a,-0.35*\a) node[midway,above] {$a$};
\draw[->] (-\a,-\a) -- ({(\XLength+1)*\a},-\a) node[below] {$m$};
\draw[->] (-\a,-\a) -- (-\a,{(\YLength+1)*\a}) node[left] {$n$};
\end{tikzpicture}
\end{document} and I convert it to vector this way: latexmlc MWE2.tex --verbose --format=html5 --graphicimages --destination=MWE2.html I would say that's really amazing! 😄 👏 🎉 Thank you for the big improvements you've made, I think this bug can be now closed! |
That does look quite respectable! Thanks again for testing and for including the example + screenshot, now we can always come back to the issue and re-test if there's some doubt of regressions in newer latexml+texlive combinations. It's encouraging we also knocked this issue down with the pgf stability upgrades 👍 |
Hello @dginev. However, if you observe well in the conversion, the arrows are rotated to a vertical and horizontal position that is not the angle of the line. I am having this problem with all arrows that are not vertical or horizontal. Do you know something about this? |
Hi @Yunelsy ! No, I am not aware of that, and most recently it has been @brucemiller progressively upgrading the tikz conversion. I think it may be very helpful if you can distill a small example and open a new issue. The smaller the example, the better, as it takes quite a long trip to debug which piece of the internals need to be fine-tuned. |
thank you for the replay @dginev, I will do that. |
Consider the following
MWE.tex
:When I convert using
I have no errors if I comment out the second line, while if I leave it I get the following errors:
I also take the chance to report that, in the first case (the one who runs fine without error) the arrows are converted into an image but the math is not; however, since the math is (in this case) part of the picture, I expect that it gets converted along with the arrows in the same png.
In this direction, I think it would be nice to have something like what you obtain if you use
which converts the
tikzpicture
environments into separate PDF's at compile time. In this way, I think you can even get rid of the errors you get with TikZ+LaTeXML (which don't occur in PDFLaTeX) when you use "unorthodox" math (like in #760).The text was updated successfully, but these errors were encountered: