TransWikia.com

Combine / nesting newcommand with def that are referencing #1, #2, etc in different ways?

TeX - LaTeX Asked by Dan-Erik Lindberg on April 16, 2021

I have a polar plot made with TikZ that I used to draw in some old documents. Now I want to use this in my document class instead of having the whole code snippet every place that I am drawing the plot.

According to this question a TikZ picture can be put inside newcommand and pass variables to it. The problem is that inside this code is also a def which is using #1, #2, etc. How can I pass variables into my custom newcommand while still using def for other variables?

documentclass[12pt]{report}
usepackage[table]{xcolor}
usepackage{tikz}
usepackage{pstricks}
usepackage{pstricks-add,pst-slpe}
usepackage{pgfmath}
usepackage{xifthen}
usetikzlibrary{decorations.text, arrows.meta,calc,shadows.blur,shadings}
begin{document}
    begin{figure}
        centering
        resizebox{.52textwidth}{!}
        {
            begin{tikzpicture}[
                % Environment Cfg
                font=Large,
                scale=1,
                % Styles
                Grid/.style={
                    loosely dotted,
                    line width=1.3pt,
                    color=black
                },
                Separator/.style={
                    thick,
                    color=black!52
                },
                Border/.style={
                    line width=1.3pt,
                    color=black!65
                },
                Border2/.style={
                    line width=2.6pt,
                    color=blue!13
                },
                Fill/.style={
                    fill=blue,
                    opacity=0.13
                }
                ]
                
                %Variables: 1:levels, 2:grid 3:number of features 4: Feature_name/quantity
                % 5: anchor align 6: numbers position 7:Relative position 8: ID
                defgoalswheelS#1#2#3#4[#5][#6](#7)(#8){%
                    begin{scope}[shift={(#7)}] 
                        %Drawing the  numbers.
                        foreach n  [count=m]  in {0,#2,...,#1}{
                            node[anchor=#5] (A) at (#6:n+0.2){n};
                        }
                        %Drawing the  grid
                        foreach n  in {0,#2,...,#1}{
                            foreach [count=i, evaluate=i as x using int(i+1)]m in {0,1,...,#3}{
                                draw[Grid](360/#3*-i:n) -- (360/#3*-x:n);
                                draw[Fill](360/#3*-i:n) -- (0,0) -- (360/#3*-x:n);
                            }
                        }   
                        %Drawing features separations.
                        foreach m [count=i] in {0,1,...,#3}{
                            draw[Separator] (0,0) -- (360/#3*-i: #1);}
                        
                        %Drawing the border
                        draw[fill=black, opacity=0.1] (0,0) circle [radius=#1];
                        draw[Border] (0,0) circle [radius=#1];
                        
                        %Drawing the names
                        foreach o/p [count=j from 0] in {#4}{
                            pgfmathparse{int(360/#3*-j)}
                            ifthenelse{pgfmathresult =90 OR pgfmathresult =270}
                            {%True
                                draw (360/#3*j:#1+0.7) node [anchor=center]{hugeo};
                            }
                            {%false
                                ifthenelse{pgfmathresult <90 OR pgfmathresult >270}
                                {% True
                                    draw (360/#3*-j:#1+0.7) node [anchor=west]{hugeo};
                                }
                                {%False
                                    draw (360/#3*-j:#1+0.7) node [anchor=east]{hugeo};
                                }
                            }
                            coordinate (#8cj) at (360/#3*-j:p);
                        }
                        
                        coordinate (#8c#3) at (#8c0);
                        foreach o/p [count=i from 0, evaluate=i as x using int(i+1)] in {#4}{%Close the perimeter
                            draw[Border2] (#8ci) -- (#8cx);
                            draw[fill=blue, opacity=.52] (#8ci) --(0,0) -- (#8cx);
                        }
                    end{scope}
                }
                
                
                % This function draws the goalswheel
                %goalswheel{levels}{grid}{number of features}{feature_name/quantity}[anchor angle][numbers direction in degrees][relative position](ID);
                goalswheelS{100}{25}{20}{
                    Mål1/50,
                    Delmål1.1/55,
                    Delmål1.2/46,
                    Delmål1.3/52,
                    Mål 2/20,
                    Delmål 2.1/24,
                    Delmål 2.2/14,
                    Delmål 2.3/22,
                    Mål 3/75,
                    Delmål 3.1/64,
                    Delmål 3.2/84,
                    Delmål 3.3/74,
                    Mål 4/35,
                    Delmål 4.1/43,
                    Delmål 4.2/34,
                    Delmål 4.3/24,
                    Mål 5/5,
                    Delmål 5.1/4,
                    Delmål 5.2/4,
                    Delmål 5.3/5
                }[90][0](25,-25)(1);
            end{tikzpicture}
        }
    end{figure}
end{document}

If you try this MWE you will also find some other oddities in the code that I would really appreciate some help with. Giving levels more than 10 will render the text smaller and smaller until it is invisible (like in the example where levels is 100), and adjusting the grid to larger spaces (like 25 units in the example) will not make the text visible. Changing the levels to 5 and grid to 1 produces visible text (but then the values for each feature also has to be reduced). Also, the anchor angle (90 degrees in the example) does nothing, which I think it used to do so maybe there was some update to TikZ? The anchor angle is meant to spin the whole graph so that you can put the axis up, down, or to the left (right is default). Anyway, those are bonus questions, what I really need is to find a way to move this code to my document class in a command or function that I can call from the .tex document.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP