Code Monkey home page Code Monkey logo

tikzpictures.jl's Introduction

TikzPictures

Build Status codecov

This library allows one to create Tikz pictures and save in various formats. It integrates with IJulia, outputting SVG images to the notebook.

This library will try to use the lualatex package already installed on the system. If the library cannot run lualatex, it will fall back to trying to use tectonic for the compilation.

Lualatex may be installed through the texlive and miktex distributions. You should have dvisvgm installed. On Ubuntu, you can get the required packages, if not already present, by running sudo apt-get install pdf2svg texlive-latex-base texlive-binaries texlive-pictures texlive-latex-extra texlive-luatex.

Note: this package will attempt to turn off interpolation in the generated SVG, but this currently only works in Chrome.

Example

using TikzPictures
tp = TikzPicture("\\draw (0,0) -- (10,10);\n\\draw (10,0) -- (0,10);\n\\node at (5,5) {tikz \$\\sqrt{\\pi}\$};", options="scale=0.25", preamble="")
save(PDF("test"), tp)
save(SVG("test"), tp)
save(TEX("test"), tp)
save(TIKZ("test"), tp)

As you can see above, you have to escape backslashes and dollar signs in LaTeX. To simplify things, this package provides the LaTeXString type, which can be constructed via L"...." without escaping backslashes or dollar signs.

tp = TikzPicture(L"""
\draw (0,0) -- (10,10);
\draw (10,0) -- (0,10);
\node at (5,5) {tikz $\sqrt{\pi}$};"""
, options="scale=0.25", preamble="")

Embedding TEX files in external documents

Compiling a standalone LaTeX file requires the Tikz code to be wrapped in a tikzpicture environment, which again is wrapped in a document environment. You can omit these wrappers if you intend to embed the output in a larger document, instead of compiling it as a standalone file.

save(TEX("test"; limit_to=:all), tp) # the default, save a complete file
save(TEX("test"; limit_to=:picture), tp) # only wrap in a tikzpicture environment
save(TEX("test"; limit_to=:data), tp) # do not wrap the Tikz code, at all

tikzpictures.jl's People

Contributors

balazsmezei avatar barche avatar dharasim avatar dressel avatar dylan-asmar avatar epatters avatar femtocleaner[bot] avatar fredrikekre avatar giordano avatar github-actions[bot] avatar h-m-h avatar juliatagbot avatar khdlr avatar khosravipasha avatar maximebouton avatar mehalter avatar mirkobunse avatar mossr avatar mykelk avatar pwl avatar rodonn avatar shushman avatar sidthekid402 avatar swt30 avatar tawheeler avatar tkelman avatar tomyun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tikzpictures.jl's Issues

Error opening file when saving PDF on Windows

Example:

tp = TikzPicture("\\draw (0,0) -- (10,10);\n\\draw (10,0) -- (0,10);\n\\node at (5,5) {tikz \$\\sqrt{\\pi}\$};", options="scale=0.25", preamble="")
save(PDF("testPic"), tp)

Error:

SystemError: opening file .\jl_465.tmp/testPic.log: No such file or directory

Stacktrace:
 [1] #systemerror#39(::Nothing, ::Function, ::String, ::Bool) at .\error.jl:106
 [2] systemerror at .\error.jl:106 [inlined]
 [3] #open#293(::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Nothing, ::Function, ::String) at .\iostream.jl:283
 [4] open at .\iostream.jl:275 [inlined]
 [5] #open#294(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::getfield(Base, Symbol("##258#259")){String}, ::String) at .\iostream.jl:367
 [6] open at .\iostream.jl:367 [inlined]
 [7] read at .\io.jl:297 [inlined]
 [8] save(::PDF, ::TikzPicture) at C:\Users\mykel\.julia\packages\TikzPictures\xOhrp\src\TikzPictures.jl:229
 [9] top-level scope at In[4]:2

Use jll binary

Tectonic is packaged as a Julia jll binary (via Yggdrasil) and could most likely solve a lot of problems people are having with TikzPictures. When using Tectonic like

Tectonic.tectonic() do tectonic_bin
     run(`$tectonic_bin paper.tex`)
end

all the required artefacts are managed by Julia and Tectonic.

For example, I'm using Tectonic for my package Books.jl and due to it, I don't have to install LaTeX in the CI job. Julia handles it for me and the users.

Would be nice to avoid the lualatex85.sty error

Whenever there is an error compiling the document, the only error message I see is

LaTeX Error: File `luatex85.sty' not found.

but the error never has anything to do with luatex85. If I compile the .tex in the terminal, I can usually figure out what the problem is. It would be nice if we could allow latex to dump all of its output so that the real error can be found.

Customize environment for TikZ picture

Would it be possible to add a field to TikzPicture that allows the LaTeX environment for TikZ pictures to be changed? My use case is tikz-cd, which uses the environment \begin{tikzcd} .. \end{tikzcd} instead of \begin{tikzpicture} ... \end{tikzpicture}.

I can implement this feature if you think it makes sense.

Initiate _tikzUseTectonic in init

Changing init from __init__() = __init__svg() to

function __init__()
    __init__svg()
    try
        success(`$(tikzCommand()) -v`)
    catch
        global _tikzUseTectonic
        _tikzUseTectonic = true
    end
end

Automatically selects tectonic upon loading. We can additionally consider adding an environment variable with which users can specify which backend they wish to use.

Happy to file a PR, any thoughts ?

Coveralls badge

Any idea on why Coveralls stopped working when we moved to the JuliaTeX org?

Undefined control sequence in TeXLive 2016

The standalone package uses the \pdfpagewidth command, which as far as I can tell was removed from LuaTeX in a recent update. TikzPictures is therefore breaking on my new installation of TeXLive 2016, which uses the updated LuaTeX:

! Undefined control sequence.
\sa@placebox ->\newpage \global \pdfpagewidth 
                                              =\wd \sa@box \global \pdfpageh...
l.20 \end{tikzpicture}

Error saving as SVG
LaTeX error

This stackoverflow topic suggests adding \RequirePackage{luatex85} as a workaround until standalone is updated.

Support PNG output

It would be useful to add support for PNG output.

While inferior to SVG in rendering quality, I think it has many use cases. Here's mine:

I want to distribute Jupyter notebooks that include the pictures generated by TikzPictures.jl . Currently the pictures are stored in the notebook as SVG. When the notebook is opened by a new user, the SVG is not trusted so the picture is not shown. The user has to rexecute the cell or explicitely trust the notebook to see the picture. See here and here for reports of this difficulty.

tikzpictures is not showing in IJulia

When I use this

using TikzPictures
tp = TikzPicture("\\draw (0,0) -- (10,10);\n\\draw (10,0) -- (0,10);\n\\node at (5,5) {tikz \$\\sqrt{\\pi}\$};", options="scale=0.25", preamble="")

I only get plain text output.

TikzPicture("\\draw (0,0) -- (10,10);\n\\draw (10,0) -- (0,10);\n\\node at (5,5) {tikz \$\\sqrt{\\pi}\$};", "scale=0.25", "", "tikzpicture", "", "", true, true)

when I try a tip found in this other issue #6

using TikzPictures
tikzDeleteIntermediate(false)
tp = TikzPicture("\\draw (0,0) -- (10,10);\n\\draw (10,0) -- (0,10);\n\\node at (5,5) {tikz \$\\sqrt{\\pi}\$};", options="scale=0.25", preamble="")
run(`lualatex tikzpicture.tex`)

I get even an error

Unable to read environment locale: exit now.
failed process: Process(`lualatex tikzpicture.tex`, ProcessExited(1)) [1]


Stacktrace:
 [1] pipeline_error
   @ ./process.jl:525 [inlined]
 [2] run(::Cmd; wait::Bool)
   @ Base ./process.jl:440
 [3] run(::Cmd)
   @ Base ./process.jl:438
 [4] top-level scope
   @ In[19]:4
 [5] eval
   @ ./boot.jl:360 [inlined]
 [6] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1094

running julia 1.6.1 on nixos 21.05

julia> versioninfo()
Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, icelake-client)

I can run both ; which lualatex and also ; which pdf2svg in the jupyter notebook and both work.
Any help is highly appreciated

! Package pgfkeys Error: I do not know the key '/tikz/box' and I am going to ig nore it.

The follwing code gives errors:

using TikzPictures

tp = TikzPicture(
L"""
\node[box] (fa) {$f_a$};
\node[left of=fa] (x1) {};
\path[line] (x1) edge[-] node[anchor=north]{$x_1$} (fa);
"""
, options="scale=0.25", preamble=""
)

Apparently the options for box and line are not yet supported. The same code works fine when used outside the TikzPictures.jl package.

! Package pgfkeys Error: I do not know the key '/tikz/box' and I am going to ig
nore it. Perhaps you misspelled it.

See the pgfkeys package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.5 \node[box]
             (fa) {$f_a$};
Error saving as SVG

! Undefined control sequence. 330 \sa@placebox ...

Hello,

I think I'm bumping against an issue that several people before me seem to have had in various contexts as far as I could see in the issues and PRs however it's still unclear to me how to fix it.

My context is the following, a Franklin.jl user would like to be able to call TikzCDs.jl (which relies on TikzPictures.jl), produce a diagram and show it on a webpage. This works fine locally, here's a screenshot (using MacTex):

Screenshot 2020-10-20 at 14 07 54

I would now like the same to happen when deploying with GitHub Action. For this purpose, I have used a deploy.yml with these lines:

- name: Install deps for Tikz
      run: |
          sudo apt-get -qq update
          sudo apt install -y pdf2svg texlive-latex-base texlive-binaries texlive-pictures texlive-latex-extra texlive-luatex

which was copied from TikzCDs' deploy script. However when the GitHub Action runs, I get

WARNING: could not import LaTeXStrings.@L_mstr into TikzPictures
328
WARNING: could not import LaTeXStrings.@L_mstr into TikzCDs
329
! Undefined control sequence.
330
\sa@placebox ->\newpage \global \pdfpagewidth 
331
                                              =\wd \sa@box \global \pdfpageh...
332
l.9 \end{tikzcd}

which crashes the build. The WARNINGs can probably be ignored as I get them locally too.
The placebox thing seems to be a known issue since you have specific issues & PRs related to it. Any idea what I could try to get this to work? Since I've got this working locally, I'm assuming it must be a dependency problem with texlive?

With apologies for the spam, cc @epatters who was trying this and @mehalter since this concerns TikzCDs too.

Thanks in advance!

Changing global working directory

Sometimes this package has the side effect of changing the current working directory for all of Julia and leaving it changed! 😲 This can result in very hard-to-diagnose unexpected behavior like files the user wanted to save in her directory ending up in this package's temporary working dir.

Of course it's fine to change directories temporarily to run commands, but it is hard to guarantee that it is changed back correctly in all cases. The two-argument version of cd() should be used to automatically enforce this. 😃

Build script

Should this have a dep/build.jl script that gives warnings and tries to install lualatex if it is missing?

Failure to precompile do to Tectonic issue

The issue MichaelHatherly/Tectonic.jl#13, prevents Tectonic from precompiling on M1 Macs until an upstream tectonic issue is resolved. Is there a way to prevent that precompile issue from propagating to TikzPictures?

From looking at the TikzPictures src, it appears that lualatex is the default engine with Tectonic being opt-in.

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Integration with Pluto.jl Notebook

Hey!

Is there any plan to integrate with the Pluto.jl notebooks?
Using tikz with Pluto would be incredible!
And it doesn't seem to be very different, but I'm very new to all of this, so idk how to help here.

Thanks!

Standalone workaround does not trigger

The workaround for standalone catches a specific error message:

if !standaloneWorkaround() && occursin("\\sa@placebox ->\\newpage \\global \\pdfpagewidth", tex_log)

For me the error message differs and hence the workaround does not kick in:

\sa@placebox ...wd \sa@box \global \pdfpageheight

I tried on two different systems (Ubuntu and Fedora) and got the same error. I can of course work around this by manually enabling the workaround. But maybe you could consider generalizing the filter (I guess replacing ->\\newpage by a wildcard should do the trick).

Error with IJulia display of TikzPictures

I try to use TikzPictures in my IJulia session. Julia v0.3.11 and the following command fails

using TikzPictures
tp = TikzPicture("\\draw (0,0) -- (10,10);\n\\draw (10,0) -- (0,10);\n\\node at (5,5) {tikz \$\\sqrt{\\pi}\$};", options="scale=0.25", preamble="")

This gives the following response:

opening file tikzpicture.svg: No such file or directory

 in systemerror at /usr/local/Cellar/julia/0.3.11/lib/julia/sys.dylib
 in open at /usr/local/Cellar/julia/0.3.11/lib/julia/sys.dylib (repeats 2 times)
 in writemime at /Users/murraytannock/.julia/v0.3/TikzPictures/src/TikzPictures.jl:216
 in sprint at iostream.jl:229
 in display_dict at /Users/murraytannock/.julia/v0.3/IJulia/src/execute_request.jl:28

It does not display the image. This is true for any Tikz I try to use. Should I report this at IJulia as well?

Enable Travis CI

We should be able to add the necessary packages (e.g., texlive) using something like this to enable Travis CI. It would be great to get Coveralls going as well.

[PkgEval] TikzPictures may have a testing issue on Julia 0.4 (2014-09-29)

PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their tests (if available) on both the stable version of Julia (0.3) and the nightly build of the unstable version (0.4). The results of this script are used to generate a package listing enhanced with testing results.

On Julia 0.4

  • On 2014-09-28 the testing status was Tests pass.
  • On 2014-09-29 the testing status changed to Package doesn't load.

Tests pass. means that PackageEvaluator found the tests for your package, executed them, and they all passed.

Package doesn't load. means that PackageEvaluator did not find tests for your package. Additionally, trying to load your package with using failed.

This error on Julia 0.4 is possibly due to recently merged pull request JuliaLang/julia#8420.
This issue was filed because your testing status became worse. No additional issues will be filed if your package remains in this state, and no issue will be filed if it improves. If you'd like to opt-out of these status-change messages, reply to this message saying you'd like to and @IainNZ will add an exception. If you'd like to discuss PackageEvaluator.jl please file an issue at the repository. For example, your package may be untestable on the test machine due to a dependency - an exception can be added.

Test log:

>>> 'Pkg.add("TikzPictures")' log
INFO: Installing LaTeXStrings v0.1.0
INFO: Installing TikzPictures v0.1.2
INFO: Package database updated

>>> 'using TikzPictures' log
Julia Version 0.4.0-dev+842
Commit e5d8c1a (2014-09-29 06:50 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

ERROR: InexactError()
 in uint32_3B_2324 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in reload_path at loading.jl:152
 in _require at loading.jl:67
 in require at loading.jl:51
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
 in _start_3B_3625 at /home/idunning/julia04/usr/bin/../lib/julia/sys.so
while loading /home/idunning/pkgtest/.julia/v0.4/TikzPictures/src/TikzPictures.jl, in expression starting on line 186
while loading /home/idunning/pkgtest/.julia/v0.4/TikzPictures/testusing.jl, in expression starting on line 2

>>> test log
no tests to run
>>> end of log

`success` function for testing of lualatex installation throws an exception when not installed

The use of success(`$(tikzCommand()) -v`) appears throughout as a test of whether lualatex is able to be used. It also shows up in the runtests.jl as success(`lualatex -v`). However, success raises an exception if the process cannot be started (https://docs.julialang.org/en/v1/base/base/#Base.success).

Therefore instead of the intended use of falling back to tectonic, we get the following error:

ERROR: IOError: could not spawn `lualatex -v`: no such file or directory (ENOENT)

I recreated this behavior on Ubuntu and MacOS (M1 processor with some modifications for tectonic use).

We can fix this by creating a helper function that catches the exception of success. I was planning on including it with my pull request for the tectonic_jll change but wanted to submit the issue in case a different approach is preferred.

precompile

Is there a reason why TikzPictures does not have precompile enabled?

PDF and SVG ouput not working on Windows on Julia 1.4

Trying to save TikzPicture as PDF or SVG on windows seems to give a LaTeX error.
I think the error lies in how the path is given to LuaLaTeX.

Example:

tp = TikzPicture("\\draw (0,0) -- (10,10);\n\\draw (10,0) -- (0,10);\n\\node at (5,5) {tikz \$\\sqrt{\\pi}\$};", options="scale=0.25", preamble="")
save(PDF("testPic"), tp)

Error:

ERROR: LaTeX error
Stacktrace:
 [1] error(::String) at .\error.jl:33
 [2] (::TikzPictures.var"#6#7"{PDF,TikzPicture,String})() at C:\Users\jesse\.julia\packages\TikzPictures\x0ZWu\src\TikzPictures.jl:269
 [3] cd(::TikzPictures.var"#6#7"{PDF,TikzPicture,String}, ::String) at .\file.jl:93
 [4] save(::PDF, ::TikzPicture) at C:\Users\jesse\.julia\packages\TikzPictures\x0ZWu\src\TikzPictures.jl:213
 [5] top-level scope at REPL[3]:1

The LaTeX error:

! Emergency stop.
<*> /jllOleMv\testPic
                  .tex
End of file on the terminal!



Here is how much of LuaTeX's memory you used:
 4 strings out of 481351
 100000,319454 words of node,token memory allocated 270 words of node memory still in use:
   1 hlist, 39 glue_spec nodes
   avail lists: 2:12,3:1,4:1,5:3
 17247 multiletter control sequences out of 65536+600000
 24 fonts using 2830079 bytes
 0i,0n,0p,0b,6s stack positions out of 5000i,500n,10000p,200000b,100000s
!  ==> Fatal error occurred, no output PDF file produced!

The temporary directory seems to be made in the root folder, of my D: drive in this case.
I could not find out whether this was wanted behaviour, but I think this directory should be local.

The problem does not appear to be with my TeX distribution: when I manually execute
lualatex --enable-write18 testpic.tex I do get the correct PDF.

Hope this is enough information.
Thank you very much for helping in advance.

UndefVarError: tex_log not defined when _run encounters an error.

I'm having an issue where I get a "tex_log not defined" error when I run "save(PDF("test"), tp)". Based on the stack trace and an inspection of the source code, it looks like "tex_log" is not declared in the _run method, such that when an error occurs the program is unable to produce an appropriate error message. But I'm not familiar enough with Julia to fix it myself, sorry!

This is the stack trace:

save(PDF("test"), tp)
UndefVarError: tex_log not defined

Stacktrace:
 [1] _run(tp::TikzPictures.TikzPicture, temp_dir::String, temp_filename::String; dvi::Bool)
   @ TikzPictures ~/.julia/packages/TikzPictures/Y2iEZ/src/TikzPictures.jl:284
 [2] _run
   @ ~/.julia/packages/TikzPictures/Y2iEZ/src/TikzPictures.jl:259 [inlined]
 [3] (::TikzPictures.var"#20#21"{PDF, TikzPictures.TikzPicture, String})()
   @ TikzPictures ~/.julia/packages/TikzPictures/Y2iEZ/src/TikzPictures.jl:302
 [4] cd(f::TikzPictures.var"#20#21"{PDF, TikzPictures.TikzPicture, String}, dir::String)
   @ Base.Filesystem ./file.jl:106
 [5] save(f::PDF, tp::TikzPictures.TikzPicture)
   @ TikzPictures ~/.julia/packages/TikzPictures/Y2iEZ/src/TikzPictures.jl:296
 [6] top-level scope
   @ In[18]:1
 [7] eval
   @ ./boot.jl:360 [inlined]
 [8] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1116

Firefox rendering issue

Running the example from the readme in a notebook:
https://gist.github.com/barche/374acaa95b706e5b48b2

This renders correctly on github and using IJulia+safari, but in IJulia+firefox the text is missing:
firefox-svg

I'm pretty sure this isn't a TikzPictures bug, but I have no idea where in the pipeline this can be fixed. Saving the embedded SVG code as a file and opening it in Firefox does render correctly, it is only when embedded in a notebook that it fails.

standalone.cls not found

On running this snippet

using TikzPictures
tp = TikzPicture("\\draw (0,0) -- (10,10);\n\\draw (10,0) -- (0,10);\n\\node at (5,5) {tikz \$\\sqrt{\\pi}\$};", options="scale=0.25", preamble="")
save(PDF("test"), tp)

I get this error in Julia (REPL)

! LaTeX Error: File `standalone.cls' not found.

Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: cls)

Enter file name: 
! Emergency stop.
<read *> 
   
l.2 
   
End of file on the terminal!



Here is how much of LuaTeX's memory you used:
 14 strings out of 494577
 100000,89155 words of node,token memory allocated 243 words of node memory still in use:
   1 dir, 2 glue, 32 glue_spec nodes
   avail lists: 2:12,3:1,4:1
 4190 multiletter control sequences out of 65536+600000
 14 fonts using 591559 bytes
 10i,0n,7p,54b,15s stack positions out of 5000i,500n,10000p,200000b,100000s
!  ==> Fatal error occurred, no output PDF file produced!

ERROR: LaTeX error
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] (::TikzPictures.var"#15#16"{PDF,TikzPicture,String})() at /home/codespace/.julia/packages/TikzPictures/T36kb/src/TikzPictures.jl:308
 [3] cd(::TikzPictures.var"#15#16"{PDF,TikzPicture,String}, ::String) at ./file.jl:104
 [4] save(::PDF, ::TikzPicture) at /home/codespace/.julia/packages/TikzPictures/T36kb/src/TikzPictures.jl:252
 [5] top-level scope at REPL[16]:1

Does this not work on Julia REPL?Do I specifically need a notebook for this?

Struggling with preamble

I am trying to define my own node style in a separate \tikzset and as far as I understood the only way to pass them to TikzPictures is to use the preamble= argument.

This is what I am trying to set:

\documentclass{article}
\usepackage{tikz}

\tikzset{
  pics/mynode/.style args={#1,#2,#3}{
     code={
       \draw (0,0) -- (1,-1) -- (2,0) -- (2,2) -- (0,2) -- (0,0);
       \node[#3] (#1) at (1,1) {#2};
     }
  }
}

\begin{document}

  \begin{tikzpicture}
      \draw (0,0) pic{mynode={A, Hi, blue}};
      \draw (0,3) pic{mynode={B, Hello, red}};
      \draw (2,1.5) pic{mynode={C, Bye,}};
      \draw[thick, blue] (A)--(B)--(C)--(A);
  \end{tikzpicture}

\end{document}

I set the preamble using:

preamble = L"""
\tikzset{
  pics/mynode/.style args={#1,#2,#3}{
     code={
       \draw (0,0) -- (1,-1) -- (2,0) -- (2,2) -- (0,2) -- (0,0);
       \node[#3] (#1) at (1,1) {#2};
     }
  }
}
"""

and then tried

using TikzPictures

tp = TikzPicture(L"""
[all exes=unit length=20cm]
\draw (0,0) -- (1,1);
\draw (1,0) -- (0,1);
\node at (0.5,0.5) {tikz $\sqrt{\pi}$};
"""
, preamble=preamble)

However, I got

TikzPicture(L"[all exes=unit length=20cm]
\draw (0,0) -- (1,1);
\draw (1,0) -- (0,1);
\node at (0.5,0.5) {tikz $\sqrt{\pi}$};
", "scale=1", L"$\tikzset{
  pics/mynode/.style args={#1,#2,#3}{
     code={
       \draw (0,0) -- (1,-1) -- (2,0) -- (2,2) -- (0,2) -- (0,0);
       \node[#3] (#1) at (1,1) {#2};
     }
  }
}
$", true)
! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.2 $
   \tikzset{

So wondering how the preamble is to be used? I played around but could not figure out.

Also I think it would be nice to provide the path to a preamble file using a environment variable, just like in PGFPlotsX.jl. I'll try to follow up with an MR.

Path for files

Is there a way to specify a particular path, something like save(PDF("results/test"), tp) instead of saving in the default folder? Currently I get an error of this form: results/results: no such file or directory (ENOENT)

update to Julia 0.4?

In the latest git version of Julia 0.4 one gets the warning

julia> using TikzPictures
WARNING: uint64(x::FloatingPoint) is deprecated, use round(Uint64,x) instead.
in depwarn at ./deprecated.jl:62
in uint64 at deprecated.jl:49
in include at ./boot.jl:253
in include_from_node1 at ./loading.jl:133
in reload_path at ./loading.jl:157
in _require at ./loading.jl:69
in require at ./loading.jl:52
while loading /home/joachim/.julia/v0.4/TikzPictures/src/TikzPictures.jl, in expression starting on line 206

which polutes notebooks using TikzPictures.

No method for LaTeXStrings

Trying to run the example from the README.md using TikzPictures 1.1.0 on julia 0.6 causes the following error:

tp = TikzPicture(L"""
\draw (0,0) -- (10,10);
\draw (10,0) -- (0,10);
\node at (5,5) {tikz $\sqrt{\pi}$};"""
, options="scale=0.25", preamble="")
MethodError: no method matching TikzPictures.TikzPicture(::LaTeXStrings.LaTeXString; options="scale=0.25", preamble="")
Closest candidates are:
  TikzPictures.TikzPicture(::String; options, preamble, usePDF2SVG, enableWrite18) at /home/moeddel/.julia/v0.6/TikzPictures/src/TikzPictures.jl:54

After `Pkg.update()`, TikzPictures won't render in IJulia notebooks

@rtompa2 originally noticed the problem.
I get the following errror:

Error saving as SVG
SystemError: opening file tikzpicture.log: No such file or directory

 in open at ./iostream.jl:90
 in open at ./iostream.jl:112
 in readall at io.jl:266
 in save at /home/tim/.julia/v0.4/TikzPictures/src/TikzPictures.jl:160
 in save at /home/tim/.julia/v0.4/TikzPictures/src/TikzPictures.jl:210
 in writemime at /home/tim/.julia/v0.4/TikzPictures/src/TikzPictures.jl:242
 in writemime at /home/tim/.julia/v0.4/PGFPlots/src/PGFPlots.jl:571
 in sprint at iostream.jl:206
 in display_dict at /home/tim/.julia/v0.4/IJulia/src/execute_request.jl:29

Could this be a problem with IJulia or Interact updating?

Support for other tex engines

Would it be difficult to add support for other engines, such as pdflatex or xelatex? I'm thinking that maybe what engine to use could be configured by the user.

Deprecation warnings

tectonic() and pdftocairo() appear to be deprecated.

When running test:

┌ Warning: tectonic() is deprecated, use the non-do-block form
│   caller = ip:0x0
└ @ Core :-1
...
┌ Warning: pdftocairo() is deprecated, use the non-do-block form
│   caller = ip:0x0
└ @ Core :-1

Tag New Release With Custom Environments

Hey, I noticed you incrementd the project version after the new Environments addition, when will this release be tagged and available? This feature will be necessary for the new TikzCDs.jl package. Thanks again for all your help!

Error when saving an Image to .tex

When saving a tikz picture that contains an image as a .tex file, the content of the .tex points to a temporary png file that is deleted.

I will try to provide a MWE to reproduce the error.
@Shushman

TikzPictures not always rendering correctly in IJulia

Using PGFPlots.jl on Ubuntu in IJulia.
Axes are not being rendered correctly in IJulia cells. The axis labels are not correctly formatted / mostly missing.
We verified that lualatex produces the correct plot, and running pdf2svg produces the correct image.

The package works on other machines. Any idea what could be locally affecting it?

tikzset

Hi! Is this possible to add an extra parameter to TikzPicture in the aim to add code for \tikzset{?
For example to change the style for arrows:

\tikzset{myarrow/.style={->,draw=black,line width=1pt}}

LaTeX code to be placed before \begin{tikzpicture}[.

Emergency Stop

Hello, I get the following error when running the pgfplots example notebook. But I basically get the same error with all codes that use TikzPictures.jl. Any idea what it might be? I'm on Mac OS, Julia 1.4. I suspect it might be an installation issue, but I don't have another machine to test it on at the moment. Thanks!

> x = [1,2,3]
> y = [2,4,1]
> plot(x, y)
TikzPictures.TikzPicture("\\begin{axis}\\addplot+ coordinates {\n(1, 2)\n(2, 4)\n(3, 1)\n};\n\\end{axis}\n", "", "\\usepackage{pgfplots}\n\\pgfplotsset{compat=newest}\n\\pgfplotsset{every axis legend/.append style={%\ncells={anchor=west}}\n}\n\\usetikzlibrary{arrows}\n\\tikzset{>=stealth'}\n", true)
! Emergency stop.
<everyjob> ...ring \\def\string \\encodingdefault{OT1}')end }
                                                  \let \f@encoding \encoding...
l.1 
  \documentclass[tikz]{standalone}
End of file on the terminal!



Here is how much of LuaTeX's memory you used:
 8 strings out of 494300
 100000,89155 words of node,token memory allocated 241 words of node memory still in use:
   1 dir, 34 glue_spec nodes
   avail lists: 2:12,3:1,4:1
 4357 multiletter control sequences out of 65536+600000
 14 fonts using 591799 bytes
 5i,0n,1p,61b,15s stack positions out of 5000i,500n,10000p,200000b,100000s
!  ==> Fatal error occurred, no output PDF file produced!

Why is limit_to not exposed for TIKZ

I tend to use \includegraphics for TIKZ pictures a lot but in this case I need them without preamble but with the .tikz file ending. Is there a reason why limit_to is set to :all only?

mutable struct TIKZ <: SaveType
filename::AbstractString
limit_to::Symbol
TIKZ(filename::AbstractString) = new(removeExtension(filename, ".tikz"), :all)
end

I can workaround this by changing limit_to after creating a TIKZ object and this seems to work just fine.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.