Skip to content
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

Struggling with preamble #49

Closed
tamasgal opened this issue Aug 7, 2019 · 1 comment
Closed

Struggling with preamble #49

tamasgal opened this issue Aug 7, 2019 · 1 comment

Comments

@tamasgal
Copy link

tamasgal commented Aug 7, 2019

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.

@tamasgal
Copy link
Author

tamasgal commented Aug 7, 2019

Oops, it turned out to be the L"..." string type, which inserts $ at the beginning and the end. Now I switched to raw"..."

@tamasgal tamasgal closed this as completed Aug 7, 2019
@mykelk mykelk mentioned this issue Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant