[pstricks] points as arguments
Werner Grundlingh
wgrundlingh at gmail.com
Thu Jun 2 21:05:14 CEST 2011
Kari,
The use of \newcommand{...} in LaTeX is described here:
http://www.complang.tuwien.ac.at/anton/latex/ltx-18.html
Your original definition was incorrect and should rather have looked like this
\newcommand{\vektori}[3]{...}
rather than this
\newcommand{\vektori[3]}{...}
Also, the use of an undefined B could have caused the problem. Here's
a complete minimal example that compiles:
\documentclass{article}
\usepackage{pstricks,pstricks-add}
\begin{document}
\newcommand{\vektori}[3]{%
\pcline[arrowsize=.3,arrows=->,linecolor=black](#1)(#2)%
\naput[npos=.55,labelsep=3pt]{\ensuremath{\vec{#3}}}%
}%
\begin{pspicture}(10,10)
\vektori{1,1}{4,4}{t}%
\end{pspicture}
\end{document}
Plain TeX \def... for macro allows for more control/freedom over how
the macro structure should look (for example, using \macro(...) or
[...] or {...} or whatever intermixed controls), while \newcommand...
limits it to using [...] and {...}.
Hope this helps,
Werner
On Thu, Jun 2, 2011 at 11:32, Kari Eloranta <kari.eloranta at gmail.com> wrote:
> On Jun 2, 2011, at 4:16 AM, Kari Eloranta wrote:
>
>> I am afraid that I do not know how to pass points as arguments. I tried to
>> define a macro
>>
>> \newcommand{\vektori[3]}{
>> \psline[arrowsize=.3,arrows=->,linecolor=black](#1)(#2)
>> \uput[-90](B){$\vec{#3}$}
>> }
>>
>> for drawing force vectors in physics.
>>
>> When I try to call the macro with
>>
>> \vektori{6,6}{5,5}{F}
>>
>> I get the error message "missing number treated as zero". Would anybody be
>> kind enough and teach me what it is I am missing here. I have tried to find
>> information from several books and internet sources without any success.
>>
>> Best regards,
>> Kari
>
>> The plain TeX macros seem to offer more control than the LaTeX versions.
>>
>> \def\vektori(#1)(#2)#3{%
>>
>> \psline[arrowsize=.3,arrows=->,linecolor=black](#1)(#2)
>>
>> \uput[-90](#1){$\vec{#3}$}
>>
>> }
>>
>> (I didn't know what B referred to.) You might find it better to use a
>> different method of attaching a label, using a point connection. For
>> example,
>>
>> \def\vektori(#1)(#2)#3{%
>>
>>
>> \pcline[arrowsize=.3,arrows=->,linecolor=black](#1)(#2)\naput[npos=.35]{$\vec{#3}$}
>>
>> }
>>
>> which draws the label .35 of the way from #1 to #2, on the left side
>> (looking from #1 to #2).
>>
>> Michael
>
> Thank you very much Michael, that solved my problem. I modified your code a
> bit
> \def\vektori(#1)(#2)#3{%
> \pcline[linewidth=2pt,
> arrowsize=.3,arrows=->,linecolor=blue](#1)(#2)\naput[npos=.55,labelsep=3pt]{$\vv{#3}$}
> }
> and now I am able to do just what I wanted. I am just curious, is it
> possible to do it in a simple way with LaTeX. Not that I would not be happy
> with pure TeX code, but I was surprised not to find any information about it
> in my LaTeX manuals.
> Best regards, Kari
> --
> **************************************************************
> Kari Eloranta
> Ketunpolku 1
> 40400 JYVÄSKYLÄ FINLAND
> Tel: +358 40 586 7654
>
> _______________________________________________
> PSTricks mailing list
> PSTricks at tug.org
> http://tug.org/mailman/listinfo/pstricks
> archive: http://www.tug.org/pipermail/pstricks/
More information about the PSTricks
mailing list