I would like to create a specific macro in order to make graph display easier using Tikz.
For this purpose, I am trying to make an environment which uses many parameters. For instance, I would like to have xMin, xMax, yMin and yMax to define from where to where to display my graph, a parameter to describe where to put the legend (below or above the axes) and so on.
Therefore, I would like to make a call like this
\begin{graphe}[xMin=-5,xMax=5,yMin=5,
yMax=5,xAxisRight=below,xAxisLeft=below,yAxisTop=right,
yAxisBottom=right,xStep=1,yStep=1,gridStep=5,xScale=1,yScale=1]
\end{graphe}
I am using xString to get the values of my different parameters. My problem is the following : when I do
\StrBetween{#1}{xMin=}{,}
for instance, I do get the "-5" as expected but this is a string chain. Therefore, using this in any Tikz call will cause an error.
Although I made quite some research on the internet, I couldn't find any way to parse the string "-5" into the number -5.
I am sure I missed something and that there must be a very easy solution which I failed to find.
Thanks in advance for the help !
Edit :
\newenvironment{graphe}[1][]
{
\StrBetween{#1}{xMin=}{,}
\newcommand{\xMin}{-5}
\newcommand{\yMin}{-5}
\newcommand{\xMax}{5}
\newcommand{\yMax}{5}
\newcommand{\xAxisRight}{above}
\newcommand{\xAxisLeft}{above}
\newcommand{\yAxisTop}{right}
\newcommand{\yAxisBottom}{right}
\newcommand{\xStep}{1}
\newcommand{\yStep}{1}
\newcommand{\quadrillageStep}{5}
\newcommand{\xScale}{1}
\newcommand{\yScale}{1}
\renewcommand{\xMin}{\StrBetween{#1}{xMin=}{,}}
\begin{center}
\begin{tikzpicture}[xscale=1]
\draw[->,>=latex,very thick] (0,0) -- (\xMax,0);
}
{
\end{tikzpicture}
\end{center}
}
The last call
\draw[->,>=latex,very thick] (\xMin,0) -- (\xMax,0);
does generate an error but If I do the call with -5
instead of \xMin
it works. Therefore I thought that this was a conversion problem.
tikzset
(because you tagged tikz) or betterpgfkeys
? This is the exact reason why they are invented. – percusse Nov 7 '17 at 20:59-
and5
but\StrBetween{#1}{xMin=}{,}
is not a list of tokens it expands to a sequence of definitions that would eventually typeset the result so it fails just as usingzz=\def\foo{1}\foo
will fail and not workzz=1
– David Carlisle Nov 7 '17 at 21:00\begin{graphe}
...\end{graphe}
. Only some stuff in the optional argument? – Werner Nov 7 '17 at 21:17