5

I tried to draw the following picture usin Tikz, but got the error message in the title of this issue.

enter image description here

This is the code I am using. Observe that the error message comes when I try to insert the node $v_0$. Can anyone tell me whats going wrong here?

\begin{tikzpicture}
\def\fin{3} %... end of the slope
\def\bot{-2} %... height of the slope
\def\mp{2} %... x-coordinate of final moto's position
%... environment
\draw[gray!50,fill=gray!50,very thick]
    (-2,0)--
        (0,0)--
        (\fin,\bot)--
        (\fin+1,\bot)--
        (\fin+1,\bot-0.2)--
        (-2,\bot-0.2)--cycle
    ;

%-> DEFINE THE MOTO PICTURE (#1=size, #2=location, #3=rotation)
\def\moto#1#2#3{
    \def\wd{#1} %... wheel axis distance and moto height
    \def\wr{#1/4} %... wheel radius
    \def\pos{#2++(0,\wr)} %... position of the very bottom point of the wheel

    %... wheels
    \draw[gray!50,very thick]
        \pos circle(\wr)
        {\pos+({#3}:\wd)} circle(\wr)
        ;
    %... chassis
    \draw[gray!50,fill=gray!50]
        {\pos+({#3+120}:{6*\wr/5})} arc({120+#3}:{#3}:{6*\wr/5})--++
            ({#3}:{\wd-12*\wr/5}) arc({#3+180}:{#3+60}:{6*\wr/5})--++
                ({#3+90}:{\wr/5}) arc({#3+60}:{#3+90}:{9*\wr/5})--++
            ({#3+120}:{\wr})--++
            ({#3+210}:{2*\wr})--++
            ({#3+180}:{3*\wr})
        ;
    %... motorcyclist
    \draw[gray!50,line width={4*\wd}]
        {\pos+({#3+60}:{6*\wr/5})}--++
            ({#3+60}:{3*\wr})
        {\pos++({#3+60}:{4*\wr})} circle({2*\wr/3})
        {\pos++({#3+60}:{3*\wr})}--++
            ({#3-10}:{2*\wr})
        ;
    %... velocity vector
    %\draw[->,gray!50,very thick]
    %    {\pos++({#3}:{\wd})++({#3+90}:{\wr})}--++
    %        ({#3}:{\wd})% node[above]{$v_0$}
    %    ;
}
%... the sizes
\draw[<->,thick,white]
    (0,0)--
        (0,\mp*\bot/\fin) node[midway,fill=gray!50]{$h$}
    ;
\draw[<->,thick,white]
    (0,\mp*\bot/\fin-0.1)--
        (\mp,\mp*\bot/\fin-0.1) node[midway,fill=gray!50]{$x$}
    ;
\draw[gray!50,dashed,thick]
    (-0.5,0.25)--
        (0,0.25) to[out=0,in=100]
        (\mp+0.25,{(\mp+0.25)*\bot/\fin})
    ;

\moto{0.5}{(-1.5,0)}{0}
    \draw[->,gray!50,very thick]
        (-1,0.3)--
            (-0.5,0.3)% node[above]{$v_0$}
        ;
    \draw[gray!50]
        (-0.5,0.3) node[above]{$v_0$}
        ;
\moto{0.5}{(\mp,\mp*\bot/\fin)}{atan(\bot/\fin)}
\end{tikzpicture}
2
  • 3
    Don't redefine \wd. \wd is a TeX (very used) primitive. Call it \wad or some other name. Oct 17, 2018 at 14:11
  • Thank you very much, @PhelypeOleinik! Can you please post as an aswer so I can mark it?
    – Brasil
    Oct 17, 2018 at 14:24

1 Answer 1

8

The problem is that you redefined TeX's \wd primitive, which gets the width of a box. Try the example below with the \def\wd{0.5} (which is what your code does when you call \moto{0.5}) uncommented:

\documentclass{article}

\begin{document}

\newbox\tempbox
\setbox\tempbox\hbox{Don't \emph{ever} redefine \TeX's internals.}

% \def\wd{0.5}
The width of the following warning is: \the\wd\tempbox

\box\tempbox

\end{document}

Once you change \wd by something that is not used by TeX then it will work.

This is one of the main reasons that LaTeX's \newcommand and its successors are recommended for end users and raise an error if a command is already defined: error messages get a whole lot more interesting if you redefine something you shouldn't.

1
  • 2
    A long term target for LaTeX3 is to express all internal functions in terms of aliases of the primitives, so redefining a primitive will not be a problem. Of course, all packages should follow suit, which is the big issue.
    – egreg
    Oct 17, 2018 at 14:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .