Seven segment display with TikZ












6














Consider the following MWE:



documentclass[border=5pt,tikz]{standalone}
usepackage{ifthen}
newcommand{binary}[3]{
pgfmathsetmacronumber{int(#1*2^0+#2*2^1+#3*2^2)}
}
newcommand{sieben}[1]{

draw[gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (.1,1.18) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,-.05) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,.55) --+ (.5,0);

ifthenelse{equal{#1}{0}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{1}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
}{}

ifthenelse{equal{#1}{2}}{
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);;
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{3}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{4}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{5}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{6}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{7}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
}{}

ifthenelse{equal{#1}{8}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{9}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{a}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

% ifnum#1>9
% draw[red,line width=3pt] (0,0) --+ (0,.5);
% draw[red,line width=3pt] (0,.6) --+ (0,.5);
% draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
% draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
% draw[red,line width=3pt] (.1,.55) --+ (.5,0);
% fi

}
begin{document}
begin{tikzpicture}[xslant=0]
sieben{a}
begin{scope}[xshift=1.5cm]
binary{1}{1}{1} % seven in dual system
sieben{number}
end{scope}
end{tikzpicture}
end{document}


Here is the output:



Screenshot



My problem is: When I uncomment the commented part in the definition of the command (ifnum#1>9 …) and I type as an argument the letter "a", I get an error. But when I comment this part, I don't.



My question is: How can I fix this error?










share|improve this question


















  • 1




    a is not a number, you should use something like sieben{1}. If you want the argument to be a hexadecimal you should use ifnum"#1 and sieben{A}.
    – Ulrike Fischer
    yesterday








  • 1




    How about ifcase#1? Happy new year!
    – marmot
    yesterday






  • 1




    @marmot: This was exactly that what I was looking for. Thank you and a happy new year!
    – current_user
    yesterday
















6














Consider the following MWE:



documentclass[border=5pt,tikz]{standalone}
usepackage{ifthen}
newcommand{binary}[3]{
pgfmathsetmacronumber{int(#1*2^0+#2*2^1+#3*2^2)}
}
newcommand{sieben}[1]{

draw[gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (.1,1.18) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,-.05) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,.55) --+ (.5,0);

ifthenelse{equal{#1}{0}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{1}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
}{}

ifthenelse{equal{#1}{2}}{
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);;
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{3}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{4}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{5}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{6}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{7}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
}{}

ifthenelse{equal{#1}{8}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{9}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{a}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

% ifnum#1>9
% draw[red,line width=3pt] (0,0) --+ (0,.5);
% draw[red,line width=3pt] (0,.6) --+ (0,.5);
% draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
% draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
% draw[red,line width=3pt] (.1,.55) --+ (.5,0);
% fi

}
begin{document}
begin{tikzpicture}[xslant=0]
sieben{a}
begin{scope}[xshift=1.5cm]
binary{1}{1}{1} % seven in dual system
sieben{number}
end{scope}
end{tikzpicture}
end{document}


Here is the output:



Screenshot



My problem is: When I uncomment the commented part in the definition of the command (ifnum#1>9 …) and I type as an argument the letter "a", I get an error. But when I comment this part, I don't.



My question is: How can I fix this error?










share|improve this question


















  • 1




    a is not a number, you should use something like sieben{1}. If you want the argument to be a hexadecimal you should use ifnum"#1 and sieben{A}.
    – Ulrike Fischer
    yesterday








  • 1




    How about ifcase#1? Happy new year!
    – marmot
    yesterday






  • 1




    @marmot: This was exactly that what I was looking for. Thank you and a happy new year!
    – current_user
    yesterday














6












6








6


0





Consider the following MWE:



documentclass[border=5pt,tikz]{standalone}
usepackage{ifthen}
newcommand{binary}[3]{
pgfmathsetmacronumber{int(#1*2^0+#2*2^1+#3*2^2)}
}
newcommand{sieben}[1]{

draw[gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (.1,1.18) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,-.05) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,.55) --+ (.5,0);

ifthenelse{equal{#1}{0}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{1}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
}{}

ifthenelse{equal{#1}{2}}{
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);;
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{3}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{4}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{5}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{6}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{7}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
}{}

ifthenelse{equal{#1}{8}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{9}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{a}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

% ifnum#1>9
% draw[red,line width=3pt] (0,0) --+ (0,.5);
% draw[red,line width=3pt] (0,.6) --+ (0,.5);
% draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
% draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
% draw[red,line width=3pt] (.1,.55) --+ (.5,0);
% fi

}
begin{document}
begin{tikzpicture}[xslant=0]
sieben{a}
begin{scope}[xshift=1.5cm]
binary{1}{1}{1} % seven in dual system
sieben{number}
end{scope}
end{tikzpicture}
end{document}


Here is the output:



Screenshot



My problem is: When I uncomment the commented part in the definition of the command (ifnum#1>9 …) and I type as an argument the letter "a", I get an error. But when I comment this part, I don't.



My question is: How can I fix this error?










share|improve this question













Consider the following MWE:



documentclass[border=5pt,tikz]{standalone}
usepackage{ifthen}
newcommand{binary}[3]{
pgfmathsetmacronumber{int(#1*2^0+#2*2^1+#3*2^2)}
}
newcommand{sieben}[1]{

draw[gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (.1,1.18) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,-.05) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,.55) --+ (.5,0);

ifthenelse{equal{#1}{0}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{1}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
}{}

ifthenelse{equal{#1}{2}}{
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);;
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{3}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{4}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{5}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
}{}

ifthenelse{equal{#1}{6}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{7}}{
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
}{}

ifthenelse{equal{#1}{8}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{9}}{
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

ifthenelse{equal{#1}{a}}{
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{}

% ifnum#1>9
% draw[red,line width=3pt] (0,0) --+ (0,.5);
% draw[red,line width=3pt] (0,.6) --+ (0,.5);
% draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
% draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
% draw[red,line width=3pt] (.1,.55) --+ (.5,0);
% fi

}
begin{document}
begin{tikzpicture}[xslant=0]
sieben{a}
begin{scope}[xshift=1.5cm]
binary{1}{1}{1} % seven in dual system
sieben{number}
end{scope}
end{tikzpicture}
end{document}


Here is the output:



Screenshot



My problem is: When I uncomment the commented part in the definition of the command (ifnum#1>9 …) and I type as an argument the letter "a", I get an error. But when I comment this part, I don't.



My question is: How can I fix this error?







tikz-pgf fun ifthenelse






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









current_usercurrent_user

3,3921637




3,3921637








  • 1




    a is not a number, you should use something like sieben{1}. If you want the argument to be a hexadecimal you should use ifnum"#1 and sieben{A}.
    – Ulrike Fischer
    yesterday








  • 1




    How about ifcase#1? Happy new year!
    – marmot
    yesterday






  • 1




    @marmot: This was exactly that what I was looking for. Thank you and a happy new year!
    – current_user
    yesterday














  • 1




    a is not a number, you should use something like sieben{1}. If you want the argument to be a hexadecimal you should use ifnum"#1 and sieben{A}.
    – Ulrike Fischer
    yesterday








  • 1




    How about ifcase#1? Happy new year!
    – marmot
    yesterday






  • 1




    @marmot: This was exactly that what I was looking for. Thank you and a happy new year!
    – current_user
    yesterday








1




1




a is not a number, you should use something like sieben{1}. If you want the argument to be a hexadecimal you should use ifnum"#1 and sieben{A}.
– Ulrike Fischer
yesterday






a is not a number, you should use something like sieben{1}. If you want the argument to be a hexadecimal you should use ifnum"#1 and sieben{A}.
– Ulrike Fischer
yesterday






1




1




How about ifcase#1? Happy new year!
– marmot
yesterday




How about ifcase#1? Happy new year!
– marmot
yesterday




1




1




@marmot: This was exactly that what I was looking for. Thank you and a happy new year!
– current_user
yesterday




@marmot: This was exactly that what I was looking for. Thank you and a happy new year!
– current_user
yesterday










2 Answers
2






active

oldest

votes


















6














Most likely I do not understand your question. But I'd like to argue that one should first check if the argument is a number (I only check if it is an a but this could be extended) and then use ifcase for the integer cases.



documentclass[border=5pt,tikz]{standalone}
usepackage{ifthen}
newcommand{binary}[3]{
pgfmathtruncatemacronumber{int(#1*2^0+#2*2^1+#3*2^2)}
}
newcommand{sieben}[1]{
draw[gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (.1,1.18) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,-.05) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,.55) --+ (.5,0);
ifthenelse{equal{#1}{a}}{%typeout{a}
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{%
ifcase#1
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
or
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);;
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
fi}}
begin{document}
begin{tikzpicture}[xslant=0]
sieben{a}
begin{scope}[xshift=1.5cm]
binary{1}{1}{1} % seven in dual system
sieben{number}
end{scope}
end{tikzpicture}
end{document}


enter image description here






share|improve this answer





















  • I meant that when I have a number which is larger then 9 I get the "E" (for error).
    – current_user
    9 hours ago












  • @current_user I just tried ` sieben{10}` and it worked. What did you try?
    – marmot
    9 hours ago



















6














A PSTricks solution only for fun purposes. I am really sorry if my algorithm is not so smart, but at least I can save more keystrokes.



Version B



documentclass[pstricks,border=12pt]{standalone}
usepackage{pst-node}
newififanewififbnewififcnewififdnewififenewififfnewififg
defseg#1{%
atruebtruectruedtrueetrueftruegtrue
ifcase#1
gfalse%0
or
afalsebfalsecfalsedfalsegfalse%1
or
bfalseefalse%2
or
bfalsecfalse%3
or
afalsecfalsedfalse%4
or
cfalseffalse%5
or
ffalse%6
or
bfalsecfalsedfalsegfalse%7
or
%8
or
cfalse%9
fi
begin{pspicture}[nodesep=12pt,linewidth=12pt,linecap=1,linecolor=red](3,6)
pnodes{s}(0,0)(3,0)(3,3)(3,6)(0,6)(0,3)
ifapcline(s3)(s4)fi
ifbpcline(s4)(s5)fi
ifcpcline(s5)(s0)fi
ifdpcline(s0)(s1)fi
ifepcline(s1)(s2)fi
iffpcline(s2)(s3)fi
ifgpcline(s2)(s5)fi
end{pspicture}}
begin{document}
foreachi in {0,1,...,9}{seg{i}}
end{document}


enter image description here



Version A



A more compact solution.



documentclass[pstricks,border=12pt]{standalone}
usepackage{pst-node}

defo#1#2#3{expandafterunlesscsname if#1endcsnamepcline(s#2)(s#3)fi}
newififanewififbnewififcnewififdnewififenewififfnewififg

defp#1{%
ifcase#1
gtrue%0
or
atruebtruectruedtruegtrue%1
or
btrueetrue%2
or
btruectrue%3
or
atruectruedtrue%4
or
ctrueftrue%5
or
ftrue%6
or
btruectruedtruegtrue%7
or
%8
or
ctrue%9
fi
begin{pspicture}[nodesep=12pt,linewidth=12pt,linecap=1,linecolor=red](3,6)
pnodes{s}(0,0)(3,0)(3,3)(3,6)(0,6)(0,3)
o{a}{3}{4}
o{b}{4}{5}
o{c}{5}{0}
o{d}{0}{1}
o{e}{1}{2}
o{f}{2}{3}
o{g}{2}{5}
end{pspicture}}
begin{document}
foreachi in {0,1,...,9}{pi}
end{document}





share|improve this answer



















  • 2




    I wonder which one saves more keystrokes: (A) letting the default value of newly created conditional macros be false and turn them true or (B or the current algorithm) in which the newly created conditional macros are set true first and change them to false later on.
    – God Must Be Crazy
    yesterday








  • 2




    The ifthen tricks are very elegant. +1
    – marmot
    yesterday






  • 1




    This is for me the simplest solution. +1!
    – current_user
    9 hours ago













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468853%2fseven-segment-display-with-tikz%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














Most likely I do not understand your question. But I'd like to argue that one should first check if the argument is a number (I only check if it is an a but this could be extended) and then use ifcase for the integer cases.



documentclass[border=5pt,tikz]{standalone}
usepackage{ifthen}
newcommand{binary}[3]{
pgfmathtruncatemacronumber{int(#1*2^0+#2*2^1+#3*2^2)}
}
newcommand{sieben}[1]{
draw[gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (.1,1.18) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,-.05) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,.55) --+ (.5,0);
ifthenelse{equal{#1}{a}}{%typeout{a}
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{%
ifcase#1
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
or
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);;
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
fi}}
begin{document}
begin{tikzpicture}[xslant=0]
sieben{a}
begin{scope}[xshift=1.5cm]
binary{1}{1}{1} % seven in dual system
sieben{number}
end{scope}
end{tikzpicture}
end{document}


enter image description here






share|improve this answer





















  • I meant that when I have a number which is larger then 9 I get the "E" (for error).
    – current_user
    9 hours ago












  • @current_user I just tried ` sieben{10}` and it worked. What did you try?
    – marmot
    9 hours ago
















6














Most likely I do not understand your question. But I'd like to argue that one should first check if the argument is a number (I only check if it is an a but this could be extended) and then use ifcase for the integer cases.



documentclass[border=5pt,tikz]{standalone}
usepackage{ifthen}
newcommand{binary}[3]{
pgfmathtruncatemacronumber{int(#1*2^0+#2*2^1+#3*2^2)}
}
newcommand{sieben}[1]{
draw[gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (.1,1.18) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,-.05) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,.55) --+ (.5,0);
ifthenelse{equal{#1}{a}}{%typeout{a}
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{%
ifcase#1
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
or
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);;
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
fi}}
begin{document}
begin{tikzpicture}[xslant=0]
sieben{a}
begin{scope}[xshift=1.5cm]
binary{1}{1}{1} % seven in dual system
sieben{number}
end{scope}
end{tikzpicture}
end{document}


enter image description here






share|improve this answer





















  • I meant that when I have a number which is larger then 9 I get the "E" (for error).
    – current_user
    9 hours ago












  • @current_user I just tried ` sieben{10}` and it worked. What did you try?
    – marmot
    9 hours ago














6












6








6






Most likely I do not understand your question. But I'd like to argue that one should first check if the argument is a number (I only check if it is an a but this could be extended) and then use ifcase for the integer cases.



documentclass[border=5pt,tikz]{standalone}
usepackage{ifthen}
newcommand{binary}[3]{
pgfmathtruncatemacronumber{int(#1*2^0+#2*2^1+#3*2^2)}
}
newcommand{sieben}[1]{
draw[gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (.1,1.18) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,-.05) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,.55) --+ (.5,0);
ifthenelse{equal{#1}{a}}{%typeout{a}
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{%
ifcase#1
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
or
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);;
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
fi}}
begin{document}
begin{tikzpicture}[xslant=0]
sieben{a}
begin{scope}[xshift=1.5cm]
binary{1}{1}{1} % seven in dual system
sieben{number}
end{scope}
end{tikzpicture}
end{document}


enter image description here






share|improve this answer












Most likely I do not understand your question. But I'd like to argue that one should first check if the argument is a number (I only check if it is an a but this could be extended) and then use ifcase for the integer cases.



documentclass[border=5pt,tikz]{standalone}
usepackage{ifthen}
newcommand{binary}[3]{
pgfmathtruncatemacronumber{int(#1*2^0+#2*2^1+#3*2^2)}
}
newcommand{sieben}[1]{
draw[gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,gray,opacity=.3,line width=3pt] (0,.6) --+ (0,.5);
draw[gray,opacity=.3,line width=3pt] (.1,1.18) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,-.05) --+ (.5,0);
draw[gray,opacity=.3,line width=3pt] (.1,.55) --+ (.5,0);
ifthenelse{equal{#1}{a}}{%typeout{a}
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
}{%
ifcase#1
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
or
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);;
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,-.05) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
draw[red,line width=3pt] (0,0) --+ (0,.5);
draw[red,line width=3pt] (0,.6) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,0) --+ (0,.5);
draw[xshift=.7cm,red,line width=3pt] (0,.6) --+ (0,.5);
draw[red,line width=3pt] (.1,1.18) --+ (.5,0);
draw[red,line width=3pt] (.1,.55) --+ (.5,0);
or
fi}}
begin{document}
begin{tikzpicture}[xslant=0]
sieben{a}
begin{scope}[xshift=1.5cm]
binary{1}{1}{1} % seven in dual system
sieben{number}
end{scope}
end{tikzpicture}
end{document}


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









marmotmarmot

89.4k4103194




89.4k4103194












  • I meant that when I have a number which is larger then 9 I get the "E" (for error).
    – current_user
    9 hours ago












  • @current_user I just tried ` sieben{10}` and it worked. What did you try?
    – marmot
    9 hours ago


















  • I meant that when I have a number which is larger then 9 I get the "E" (for error).
    – current_user
    9 hours ago












  • @current_user I just tried ` sieben{10}` and it worked. What did you try?
    – marmot
    9 hours ago
















I meant that when I have a number which is larger then 9 I get the "E" (for error).
– current_user
9 hours ago






I meant that when I have a number which is larger then 9 I get the "E" (for error).
– current_user
9 hours ago














@current_user I just tried ` sieben{10}` and it worked. What did you try?
– marmot
9 hours ago




@current_user I just tried ` sieben{10}` and it worked. What did you try?
– marmot
9 hours ago











6














A PSTricks solution only for fun purposes. I am really sorry if my algorithm is not so smart, but at least I can save more keystrokes.



Version B



documentclass[pstricks,border=12pt]{standalone}
usepackage{pst-node}
newififanewififbnewififcnewififdnewififenewififfnewififg
defseg#1{%
atruebtruectruedtrueetrueftruegtrue
ifcase#1
gfalse%0
or
afalsebfalsecfalsedfalsegfalse%1
or
bfalseefalse%2
or
bfalsecfalse%3
or
afalsecfalsedfalse%4
or
cfalseffalse%5
or
ffalse%6
or
bfalsecfalsedfalsegfalse%7
or
%8
or
cfalse%9
fi
begin{pspicture}[nodesep=12pt,linewidth=12pt,linecap=1,linecolor=red](3,6)
pnodes{s}(0,0)(3,0)(3,3)(3,6)(0,6)(0,3)
ifapcline(s3)(s4)fi
ifbpcline(s4)(s5)fi
ifcpcline(s5)(s0)fi
ifdpcline(s0)(s1)fi
ifepcline(s1)(s2)fi
iffpcline(s2)(s3)fi
ifgpcline(s2)(s5)fi
end{pspicture}}
begin{document}
foreachi in {0,1,...,9}{seg{i}}
end{document}


enter image description here



Version A



A more compact solution.



documentclass[pstricks,border=12pt]{standalone}
usepackage{pst-node}

defo#1#2#3{expandafterunlesscsname if#1endcsnamepcline(s#2)(s#3)fi}
newififanewififbnewififcnewififdnewififenewififfnewififg

defp#1{%
ifcase#1
gtrue%0
or
atruebtruectruedtruegtrue%1
or
btrueetrue%2
or
btruectrue%3
or
atruectruedtrue%4
or
ctrueftrue%5
or
ftrue%6
or
btruectruedtruegtrue%7
or
%8
or
ctrue%9
fi
begin{pspicture}[nodesep=12pt,linewidth=12pt,linecap=1,linecolor=red](3,6)
pnodes{s}(0,0)(3,0)(3,3)(3,6)(0,6)(0,3)
o{a}{3}{4}
o{b}{4}{5}
o{c}{5}{0}
o{d}{0}{1}
o{e}{1}{2}
o{f}{2}{3}
o{g}{2}{5}
end{pspicture}}
begin{document}
foreachi in {0,1,...,9}{pi}
end{document}





share|improve this answer



















  • 2




    I wonder which one saves more keystrokes: (A) letting the default value of newly created conditional macros be false and turn them true or (B or the current algorithm) in which the newly created conditional macros are set true first and change them to false later on.
    – God Must Be Crazy
    yesterday








  • 2




    The ifthen tricks are very elegant. +1
    – marmot
    yesterday






  • 1




    This is for me the simplest solution. +1!
    – current_user
    9 hours ago


















6














A PSTricks solution only for fun purposes. I am really sorry if my algorithm is not so smart, but at least I can save more keystrokes.



Version B



documentclass[pstricks,border=12pt]{standalone}
usepackage{pst-node}
newififanewififbnewififcnewififdnewififenewififfnewififg
defseg#1{%
atruebtruectruedtrueetrueftruegtrue
ifcase#1
gfalse%0
or
afalsebfalsecfalsedfalsegfalse%1
or
bfalseefalse%2
or
bfalsecfalse%3
or
afalsecfalsedfalse%4
or
cfalseffalse%5
or
ffalse%6
or
bfalsecfalsedfalsegfalse%7
or
%8
or
cfalse%9
fi
begin{pspicture}[nodesep=12pt,linewidth=12pt,linecap=1,linecolor=red](3,6)
pnodes{s}(0,0)(3,0)(3,3)(3,6)(0,6)(0,3)
ifapcline(s3)(s4)fi
ifbpcline(s4)(s5)fi
ifcpcline(s5)(s0)fi
ifdpcline(s0)(s1)fi
ifepcline(s1)(s2)fi
iffpcline(s2)(s3)fi
ifgpcline(s2)(s5)fi
end{pspicture}}
begin{document}
foreachi in {0,1,...,9}{seg{i}}
end{document}


enter image description here



Version A



A more compact solution.



documentclass[pstricks,border=12pt]{standalone}
usepackage{pst-node}

defo#1#2#3{expandafterunlesscsname if#1endcsnamepcline(s#2)(s#3)fi}
newififanewififbnewififcnewififdnewififenewififfnewififg

defp#1{%
ifcase#1
gtrue%0
or
atruebtruectruedtruegtrue%1
or
btrueetrue%2
or
btruectrue%3
or
atruectruedtrue%4
or
ctrueftrue%5
or
ftrue%6
or
btruectruedtruegtrue%7
or
%8
or
ctrue%9
fi
begin{pspicture}[nodesep=12pt,linewidth=12pt,linecap=1,linecolor=red](3,6)
pnodes{s}(0,0)(3,0)(3,3)(3,6)(0,6)(0,3)
o{a}{3}{4}
o{b}{4}{5}
o{c}{5}{0}
o{d}{0}{1}
o{e}{1}{2}
o{f}{2}{3}
o{g}{2}{5}
end{pspicture}}
begin{document}
foreachi in {0,1,...,9}{pi}
end{document}





share|improve this answer



















  • 2




    I wonder which one saves more keystrokes: (A) letting the default value of newly created conditional macros be false and turn them true or (B or the current algorithm) in which the newly created conditional macros are set true first and change them to false later on.
    – God Must Be Crazy
    yesterday








  • 2




    The ifthen tricks are very elegant. +1
    – marmot
    yesterday






  • 1




    This is for me the simplest solution. +1!
    – current_user
    9 hours ago
















6












6








6






A PSTricks solution only for fun purposes. I am really sorry if my algorithm is not so smart, but at least I can save more keystrokes.



Version B



documentclass[pstricks,border=12pt]{standalone}
usepackage{pst-node}
newififanewififbnewififcnewififdnewififenewififfnewififg
defseg#1{%
atruebtruectruedtrueetrueftruegtrue
ifcase#1
gfalse%0
or
afalsebfalsecfalsedfalsegfalse%1
or
bfalseefalse%2
or
bfalsecfalse%3
or
afalsecfalsedfalse%4
or
cfalseffalse%5
or
ffalse%6
or
bfalsecfalsedfalsegfalse%7
or
%8
or
cfalse%9
fi
begin{pspicture}[nodesep=12pt,linewidth=12pt,linecap=1,linecolor=red](3,6)
pnodes{s}(0,0)(3,0)(3,3)(3,6)(0,6)(0,3)
ifapcline(s3)(s4)fi
ifbpcline(s4)(s5)fi
ifcpcline(s5)(s0)fi
ifdpcline(s0)(s1)fi
ifepcline(s1)(s2)fi
iffpcline(s2)(s3)fi
ifgpcline(s2)(s5)fi
end{pspicture}}
begin{document}
foreachi in {0,1,...,9}{seg{i}}
end{document}


enter image description here



Version A



A more compact solution.



documentclass[pstricks,border=12pt]{standalone}
usepackage{pst-node}

defo#1#2#3{expandafterunlesscsname if#1endcsnamepcline(s#2)(s#3)fi}
newififanewififbnewififcnewififdnewififenewififfnewififg

defp#1{%
ifcase#1
gtrue%0
or
atruebtruectruedtruegtrue%1
or
btrueetrue%2
or
btruectrue%3
or
atruectruedtrue%4
or
ctrueftrue%5
or
ftrue%6
or
btruectruedtruegtrue%7
or
%8
or
ctrue%9
fi
begin{pspicture}[nodesep=12pt,linewidth=12pt,linecap=1,linecolor=red](3,6)
pnodes{s}(0,0)(3,0)(3,3)(3,6)(0,6)(0,3)
o{a}{3}{4}
o{b}{4}{5}
o{c}{5}{0}
o{d}{0}{1}
o{e}{1}{2}
o{f}{2}{3}
o{g}{2}{5}
end{pspicture}}
begin{document}
foreachi in {0,1,...,9}{pi}
end{document}





share|improve this answer














A PSTricks solution only for fun purposes. I am really sorry if my algorithm is not so smart, but at least I can save more keystrokes.



Version B



documentclass[pstricks,border=12pt]{standalone}
usepackage{pst-node}
newififanewififbnewififcnewififdnewififenewififfnewififg
defseg#1{%
atruebtruectruedtrueetrueftruegtrue
ifcase#1
gfalse%0
or
afalsebfalsecfalsedfalsegfalse%1
or
bfalseefalse%2
or
bfalsecfalse%3
or
afalsecfalsedfalse%4
or
cfalseffalse%5
or
ffalse%6
or
bfalsecfalsedfalsegfalse%7
or
%8
or
cfalse%9
fi
begin{pspicture}[nodesep=12pt,linewidth=12pt,linecap=1,linecolor=red](3,6)
pnodes{s}(0,0)(3,0)(3,3)(3,6)(0,6)(0,3)
ifapcline(s3)(s4)fi
ifbpcline(s4)(s5)fi
ifcpcline(s5)(s0)fi
ifdpcline(s0)(s1)fi
ifepcline(s1)(s2)fi
iffpcline(s2)(s3)fi
ifgpcline(s2)(s5)fi
end{pspicture}}
begin{document}
foreachi in {0,1,...,9}{seg{i}}
end{document}


enter image description here



Version A



A more compact solution.



documentclass[pstricks,border=12pt]{standalone}
usepackage{pst-node}

defo#1#2#3{expandafterunlesscsname if#1endcsnamepcline(s#2)(s#3)fi}
newififanewififbnewififcnewififdnewififenewififfnewififg

defp#1{%
ifcase#1
gtrue%0
or
atruebtruectruedtruegtrue%1
or
btrueetrue%2
or
btruectrue%3
or
atruectruedtrue%4
or
ctrueftrue%5
or
ftrue%6
or
btruectruedtruegtrue%7
or
%8
or
ctrue%9
fi
begin{pspicture}[nodesep=12pt,linewidth=12pt,linecap=1,linecolor=red](3,6)
pnodes{s}(0,0)(3,0)(3,3)(3,6)(0,6)(0,3)
o{a}{3}{4}
o{b}{4}{5}
o{c}{5}{0}
o{d}{0}{1}
o{e}{1}{2}
o{f}{2}{3}
o{g}{2}{5}
end{pspicture}}
begin{document}
foreachi in {0,1,...,9}{pi}
end{document}






share|improve this answer














share|improve this answer



share|improve this answer








edited 13 hours ago

























answered yesterday









God Must Be CrazyGod Must Be Crazy

5,90211039




5,90211039








  • 2




    I wonder which one saves more keystrokes: (A) letting the default value of newly created conditional macros be false and turn them true or (B or the current algorithm) in which the newly created conditional macros are set true first and change them to false later on.
    – God Must Be Crazy
    yesterday








  • 2




    The ifthen tricks are very elegant. +1
    – marmot
    yesterday






  • 1




    This is for me the simplest solution. +1!
    – current_user
    9 hours ago
















  • 2




    I wonder which one saves more keystrokes: (A) letting the default value of newly created conditional macros be false and turn them true or (B or the current algorithm) in which the newly created conditional macros are set true first and change them to false later on.
    – God Must Be Crazy
    yesterday








  • 2




    The ifthen tricks are very elegant. +1
    – marmot
    yesterday






  • 1




    This is for me the simplest solution. +1!
    – current_user
    9 hours ago










2




2




I wonder which one saves more keystrokes: (A) letting the default value of newly created conditional macros be false and turn them true or (B or the current algorithm) in which the newly created conditional macros are set true first and change them to false later on.
– God Must Be Crazy
yesterday






I wonder which one saves more keystrokes: (A) letting the default value of newly created conditional macros be false and turn them true or (B or the current algorithm) in which the newly created conditional macros are set true first and change them to false later on.
– God Must Be Crazy
yesterday






2




2




The ifthen tricks are very elegant. +1
– marmot
yesterday




The ifthen tricks are very elegant. +1
– marmot
yesterday




1




1




This is for me the simplest solution. +1!
– current_user
9 hours ago






This is for me the simplest solution. +1!
– current_user
9 hours ago




















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f468853%2fseven-segment-display-with-tikz%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1300-talet

1300-talet

Has there ever been an instance of an active nuclear power plant within or near a war zone?