TikZ picture new feature doesn't really work
See original GitHub issueDisable all the other extensions except for LaTeX Workshop, and check that you still see this issue. [Required]
Done.
Make sure to visit the wiki FAQ before filling an issue.
Done.
Describe the bug [Required]
I was (and am) literally very surprised to see the “View TikzPicture” a few days ago – never thought that such a feature will ever be implemented. After some days of using and checking, I think there are still some problems to be considered:
- LaTeX Workshop doesn’t recognize 90% of the TikZ pictures in my document, although they are all bounded by
\begin{tikzpicture}[something]
and\end{tikzpicture}
. - Surprisingly, all recognized TikZ pictures are surrounded by one custom-defined command (in my case it is
\centertikz
) (see screenshot below). Even more, two adjacent TikZ pictures are recognized as one. - And, none of these buttons work 😦 There are some cases it opens a PDF file which has literally nothing but some text (maybe because the feature does not take the preamble into account which leads to some kinds of compilation errors). In some rare cases (which I can not reproduce right now, but I have encountered before), no PDF file is opened at all and error “PDF file not found” is reported by the PDF viewer.
Last, but not least, could you please change “TikzPicture” to “TikZ picture”, or even better “TikZ picture”? The official “logo” of the package is “TikZ”.
Expected behavior Exactly what we all expect.
Logs [Required]
LaTeX Workshop Output [Required]
I paste the related part (everything that is shown after I pressing the button). The other lines are not related IMHO.[15:26:24] Serving PDF file at http://localhost:51814/viewer.html?file=pdf..QyUzQSU1Q1VzZXJzJTVDQU5IVEFOfjElNUNBcHBEYXRhJTVDTG9jYWwlNUNUZW1wJTVDdnNjb2RlLWxhdGV4d29ya3Nob3AlNUN0aWt6cHJldmlldy1wcm9ibGVtLXR2d3RsNSU1Q3Rpa3pwaWN0dXJlLTcwMzgwODQwLnBkZg
[15:26:24] The encoded path is C:\Users\ANHTAN~1\AppData\Local\Temp\vscode-latexworkshop\tikzpreview-problem-tvwtl5\tikzpicture-70380840.pdf
[15:26:25] Open PDF tab for C:\Users\ANHTAN~1\AppData\Local\Temp\vscode-latexworkshop\tikzpreview-problem-tvwtl5\tikzpicture-70380840.pdf
[15:26:26] No PDF viewer connected for C:\Users\ANHTAN~1\AppData\Local\Temp\vscode-latexworkshop\tikzpreview-problem-tvwtl5\tikzpicture-70380840.pdf
[15:26:26] Serving PDF file at http://localhost:51814/viewer.html?file=pdf..QyUzQSU1Q1VzZXJzJTVDQU5IVEFOfjElNUNBcHBEYXRhJTVDTG9jYWwlNUNUZW1wJTVDdnNjb2RlLWxhdGV4d29ya3Nob3AlNUN0aWt6cHJldmlldy1wcm9ibGVtLXR2d3RsNSU1Q3Rpa3pwaWN0dXJlLTcwMzgwODQwLnBkZg
[15:26:26] The encoded path is C:\Users\ANHTAN~1\AppData\Local\Temp\vscode-latexworkshop\tikzpreview-problem-tvwtl5\tikzpicture-70380840.pdf
[15:26:26] Open PDF tab for C:\Users\ANHTAN~1\AppData\Local\Temp\vscode-latexworkshop\tikzpreview-problem-tvwtl5\tikzpicture-70380840.pdf
[15:26:28] Handle data type: open
[15:26:28] Handle data type: open
[15:26:28] Preview PDF file: c:\Users\ANHTAN~1\AppData\Local\Temp\vscode-latexworkshop\tikzpreview-problem-tvwtl5\tikzpicture-70380840.pdf
[15:26:28] Preview PDF file: c:\Users\ANHTAN~1\AppData\Local\Temp\vscode-latexworkshop\tikzpreview-problem-tvwtl5\tikzpicture-70380840.pdf
[15:26:28] Handle data type: loaded
[15:26:28] Handle data type: loaded
Developer Tools Console [Required]
latexmkrc
seems to have trouble compiling the TikZ pictures.
Screenshots In the following screenshot, there are no buttons.
In the following screenshot, the middle TikZ picture is not recognized.
In the following screenshot, it is expected to be a graph.
\begin{tikzpicture}[font=\footnotesize,>=stealth]
\draw[<->] (3.5,0) -| (0,2.5) node[at start,below] {$d$} node[at end,left] {$V$};
\path (0,0) node[below] {$X$} (1.5,0) node[below] {$P$} (3,0) node[below] {$Y$};
\fill (0,0) circle (1.5pt) (1.5,0) circle (1.5pt) (3,0) circle (1.5pt);
\draw[thick] (0,.5) -- (3,2);
\end{tikzpicture}
Desktop [Required]:
- OS: Windows 10
- VS Code version: 1.36.1
- Extension version: 7.2.0
Additional context
If necessary, this is my mysterious \centertikz
command. It is a workaround for centering elements in the middle of the baseline. I can’t figure out how it affects the feature, but as I can see, it does affect the feature.
\newbox\mybox
\def\centertikz#1{%
\setbox\mybox\hbox{#1}%
\raisebox{-0.5\dimexpr\ht\mybox+\dp\mybox}{\copy\mybox}%
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:18 (12 by maintainers)
Top GitHub Comments
@joulev I find it interesting that this
\tikzset
still isn’t recognised. You can see your document and the updated regex here https://regex101.com/r/1xix9x/1 and it looks like it should be included.Using your
\tikzset
MWE it seems to work for me.Preamble.tex
tikzpicture-XYZ.tex
Some Thoughts
I notice in your compilation log that you are using MiKTeX and have the following line
as such my current suspicion is that the
preamble.fmt
file isn’t being used for the compilation.For comparison with texlive on Linux I get this:
My compilation log
Of particular note to me is the line
CUSTOMISED FORMAT: "preamble "
which doesn’t appear on your log.I’ll have a look and see if MiKTeX works differently and come back. Thanks for being a willing test subject 😛
@trevorgunn thank you for helping with instructions on how to run the branch.
@joulev Edit: The easiest way to download the code is to download it as a
.zip
file through Github. I wrote about how to clone repositories earlier which you may feel free to skip.The procedure to clone a repository is with the
git
command (https://git-scm.com/). Normally this would just begit clone https://github.com/tecosaur/LaTeX-Workshop.git
but since you want a different branch, you want to specify that as well:Also possible is to clone the whole thing and then
checkout
to the correct branch:Once you’re there, you can type
git log
to check that “Expand maximum bracket nesting in tikzpreview regex” was the latest commit (so you know you have the right branch. Pressq
to exit the log.Now you can try
npm install
and hopefully that works. (It might produce a couple warnings, that is to be expected.) Check that you now have a directory callednode_modules
. Note: you must run this command from inside the LaTeX-Workshop source directory. Use thecd
(change directory) command to get to it. E.g. if you unzipped inside your Downloads folder:cd C:\User\Username\Downloads\LaTeX-Workshop
. The command also accept relative paths. E.g.cd Downloads\LaTeX-Workshop
will work if your current directory isC:\User\Username\
.You can now open up the directory in VSCode and launch, but you may also find it easier to instead run
npm run compile
which will produce a folder calledout
which you can copy toC:\User\Username\.vscode\extensions\james-yu.latex-workshop-7.2.0\
. (This is what launching does except launching restores the original extension when it closes.)