I am making a tikz library and I would like to use an optional parameter. So far, I have the following code
The tikzlibraryquestion.code.tex
file is
\usepackage{question}
\tikzset{
question/.pic={
\question@draw
},
}
There is a question.sty
file
\ProvidesPackage{question}
\RequirePackage{tikz}
\newcommand*{\mycircle}[1][]{
\tikzset{%
/mycircle/.cd,#1}\mycircle@draw%
}
\tikzset{
/mycircle/.cd,
/mycircle/tilt/.code = 0 \def\mycircle@tilt{#1},
}
\def\mycircle@draw{
\draw (0, 0) circle (1);
\begin{scope}[rotate=\mycircle@tilt]
\draw (0, 0) -- (0, 1);
\end{scope}
}
Finally, the example of use
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{question}
\begin{document}
\begin{tikzpicture}
\mycircle[tilt=23]
\end{tikzpicture}
\begin{tikzpicture}
\mycircle
\end{tikzpicture}
\end{document}
How do I change the .sty
file so that the tilt
parameter be optional ?
pic
instead of a macro? This would be so much easier and more natural.pic
s before