question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TikZ picture new feature doesn't really work

See original GitHub issue

Disable 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. a

Screenshots In the following screenshot, there are no buttons. a

In the following screenshot, the middle TikZ picture is not recognized. a

In the following screenshot, it is expected to be a graph. a

\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:closed
  • Created 4 years ago
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
tecosaurcommented, Jul 24, 2019

@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.

image

Preamble.tex

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzset{
    ->-/.style={
        postaction=decorate,
        decoration={markings,mark=at position #1 with \arrow{>}}
    }
}

\pdfcompresslevel=0
\pdfobjcompresslevel=0

\begin{document}\end{document}

tikzpicture-XYZ.tex

%&preamble
\begin{document}
\begin{tikzpicture}
        \draw[->-=0.5] (0,0) -- (3,-2);
    \end{tikzpicture}
\end{document}

Some Thoughts

I notice in your compilation log that you are using MiKTeX and have the following line

! LaTeX Error: Environment tikzpicture undefined.

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
Latexmk: This is Latexmk, John Collins, 17 Jan. 2018, version: 4.55.
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': Rules & subrules not known to be previously run:
   pdflatex
Rule 'pdflatex': The following rules & subrules became out-of-date:
      'pdflatex'
------------
Run number 1 of rule 'pdflatex'
------------
------------
Running 'pdflatex  -recorder  "tikzpicture-39616869.tex"'
------------
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=preamble)
 restricted \write18 enabled.
entering extended mode
(./tikzpicture-39616869.tex
LaTeX2e <2018-04-01> patch level 2
Babel <3.18> and hyphenation patterns for 84 language(s) loaded.

==============================================================================
JOB NAME         : "tikzpicture-39616869"
CUSTOMISED FORMAT: "preamble"
PRELOADED FILES:
standalone.cls    2018/03/26 v1.3a Class to compile TeX sub-files standalone
shellesc.sty    2016/06/07 v0.02a unified shell escape interface for LaTeX
ifluatex.sty    2016/05/16 v1.4 Provides the ifluatex switch (HO)
   ifpdf.sty    2017/03/15 v3.2 Provides the ifpdf switch
 ifxetex.sty    2010/09/12 v0.6 Provides ifxetex conditional
 xkeyval.sty    2014/12/03 v2.7a package option processing (HA)
 xkeyval.tex    2014/12/03 v2.7a key=value parser (HA)
standalone.cfg    2018/03/26 v1.3a Default configuration file for 'standalone' 
class
 article.cls    2014/09/29 v1.4h Standard LaTeX document class
  size10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
bmc-color.sty    2019/06/09 Colour functionality used in the BMC class
etoolbox.sty    2018/02/11 v2.5e e-TeX tools for LaTeX (JAW)
kvoptions.sty    2016/05/16 v3.12 Key value format for package options (HO)
 ltxcmds.sty    2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
kvsetkeys.sty    2016/05/16 v1.17 Key value parser (HO)
infwarerr.sty    2016/05/16 v1.4 Providing info/warning/error messages (HO)
etexcmds.sty    2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
 ifdraft.sty    2016/05/16 v1.4 Detect class options draft and final (HO)
  xcolor.sty    2016/05/11 v2.12 LaTeX color extensions (UK)
   color.cfg    2016/01/02 v1.6 sample color configuration
  pdftex.def    2018/01/08 v1.0l Graphics/color driver for pdftex
colortbl.sty    2012/02/13 v1.0a Color table columns (DPC)
   array.sty    2018/04/07 v2.4g Tabular extension package (FMi)
dvipsnam.def    2016/06/17 v3.0m Driver-dependent file (DPC,SPQR)
  svgnam.def    2016/05/11 v2.12 Predefined colors according to SVG 1.1 (UK)
bmc-maths.sty    2019/06/09 Maths functionality used in the BMC class
 amsmath.sty    2017/09/02 v2.17a AMS math features
 amstext.sty    2000/06/29 v2.01 AMS text
  amsgen.sty    1999/11/30 v2.0 generic functions
  amsbsy.sty    1999/11/29 v1.2d Bold Symbols
  amsopn.sty    2016/03/08 v2.02 operator names
 amssymb.sty    2013/01/14 v3.01 AMS font symbols
amsfonts.sty    2013/01/14 v3.01 Basic AMSFonts support
   xfrac.sty    2018/02/21 L3 Experimental split-level fractions
   expl3.sty    2018/03/05 L3 programming layer (loader) 
expl3-code.tex    2018/03/05 L3 programming layer 
l3pdfmode.def    2017/03/18 v L3 Experimental driver: PDF mode
graphicx.sty    2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
graphics.sty    2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg    2016/06/04 v1.11 sample graphics configuration
l3keys2e.sty    2018/02/21 LaTeX2e option processing using LaTeX3 keys
textcomp.sty    2017/04/05 v2.0i Standard LaTeX package
  ts1enc.def    2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
  ts1enc.dfu    2018/04/05 v1.2c UTF-8 support for inputenc
  xparse.sty    2018/02/21 L3 Experimental document command parser
xtemplate.sty    2018/02/21 L3 Experimental prototype document functions
  cancel.sty    2013/04/12 v2.2 Cancel math terms
mathtools.sty    2018/01/08 v1.21 mathematical typesetting tools
    calc.sty    2017/05/25 v4.3 Infix arithmetic (KKT,FJ)
 mhsetup.sty    2017/03/31 v1.3 programming setup (MH)
    tikz.sty    2015/08/07 v3.0.1a (rcs-revision 1.151)
     pgf.sty    2015/08/07 v3.0.1a (rcs-revision 1.15)
  pgfrcs.sty    2015/08/07 v3.0.1a (rcs-revision 1.31)
everyshi.sty    2001/05/15 v3.00 EveryShipout Package (MS)
  pgfrcs.code.tex
 pgfcore.sty    2010/04/11 v3.0.1a (rcs-revision 1.7)
  pgfsys.sty    2014/07/09 v3.0.1a (rcs-revision 1.48)
  pgfsys.code.tex
pgfsyssoftpath.code.tex    2013/09/09  (rcs-revision 1.9)
pgfsysprotocol.code.tex    2006/10/16  (rcs-revision 1.4)
 pgfcore.code.tex
pgfcomp-version-0-65.sty    2007/07/03 v3.0.1a (rcs-revision 1.7)
pgfcomp-version-1-18.sty    2007/07/23 v3.0.1a (rcs-revision 1.1)
  pgffor.sty    2013/12/13 v3.0.1a (rcs-revision 1.25)
 pgfkeys.sty    
 pgfkeys.code.tex
 pgfmath.sty    
 pgfmath.code.tex
  pgffor.code.tex
    tikz.code.tex
    umsa.fd    2013/01/14 v3.01 AMS symbols A
    umsb.fd    2013/01/14 v3.01 AMS symbols B

==============================================================================
(mylatexformat)Info: start reading document "tikzpicture-39616869"
(mylatexformat)      on input line 2. (\begin{document})
==============================================================================
(./tikzpicture-39616869.aux) (/usr/share/texmf-dist/tex/latex/base/ts1cmr.fd)
(/usr/share/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/share/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/share/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/share/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(/usr/share/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty)
(/usr/share/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
ABD: EveryShipout initializing macros [1] (./tikzpicture-39616869.aux) )
Output written on tikzpicture-39616869.pdf (1 page, 1585 bytes).
Transcript written on tikzpicture-39616869.log.
=== TeX engine is 'pdfTeX'
Latexmk: Log file says output to 'tikzpicture-39616869.pdf'
Latexmk: All targets (tikzpicture-39616869.pdf) are up-to-date

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.

1reaction
trevorgunncommented, Jul 24, 2019

@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 be git clone https://github.com/tecosaur/LaTeX-Workshop.git but since you want a different branch, you want to specify that as well:

git clone --single-branch --branch tikzpreview-fixes https://github.com/tecosaur/LaTeX-Workshop.git
cd LaTeX-Workshop
npm install

Also possible is to clone the whole thing and then checkout to the correct branch:

git clone https://github.com/tecosaur/LaTeX-Workshop.git
cd LaTex-Workshop
git checkout tikzpreview-fixes

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. Press q 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 called node_modules. Note: you must run this command from inside the LaTeX-Workshop source directory. Use the cd (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 is C:\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 called out which you can copy to C:\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.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

tikzpicture will not display - TeX - LaTeX Stack Exchange
I'm using the tikz package, so I'm not sure what it will not display. Any advice? I'm really new to LaTeX. tikz-pgf.
Read more >
The tikzmark package - TeXDoc
v1.2 of the tikzmark package introduced a new variant of \tikzmark which works inside a tikzpicture. One feature of \tikzmark which isn't part....
Read more >
Tutorial: A Picture for Karl's Students - PGF/TikZ Manual
This tutorial is intended for new users of TikZ, explaining features of TikZ ... It works like \draw, only it does not draw...
Read more >
How to make beautiful math graphics using Tikz & LaTeX
In this video we're going to talk about making diagrams and other graphics using the tikz package in LaTeX. This package makes it...
Read more >
Why do I keep getting the compile timeout error message?
There are several ways you can externalize the TikZ pictures so that LaTeX doesn't have to redraw them from scratch every time it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found