## LaTeX forum ⇒ General ⇒ Issues when using \put in a command definition

LaTeX specific issues not fitting into one of the other forums of this category.
migf
Posts: 11
Joined: Mon Feb 18, 2013 2:33 pm

### Issues when using \put in a command definition

I need a command that uses \put to add a hyperlink to a picture and defined it like this
\newcommand{\myput}[3]{\put(#1){\makebox(0,0){\hyperlink{#2}{#3}}}}

This command is used in the context of a \multido loop from the package of same name, e.g.
\myput{550,300}{lnkB.2}{$\rightarrow$}

but this raises the error
! Illegal unit of measure (pt inserted).

Is there any error in my definition or is there some limitation on the way \put can be used?

Thanks in advance for any help.

Stefan Kottwitz
Posts: 8598
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Can you provide some code context? Can you provide a minimal working example? (Nobody can test these two lines without a small document, and one has to guess which packages to use.)

Stefan

migf
Posts: 11
Joined: Mon Feb 18, 2013 2:33 pm
Sorry, I did not add a MWE because I thought this would be some basic problem in the command definition.

In fact it is not: to reproduce the error I had to use the multido package and also the listofitems one.


The error message is
! Illegal unit of measure (pt inserted).<to be read again>                    ]l.34   \addlist{1,2;7,4}                        % list of x,y coordinates

It seems there are problems with the listofitems package. A simpler version of this MWE gave another error: if \addlist is defined by
\newcommand{\addlist}[1]{%\setsepchar{;}\readlist\lOfItems{#1}%\multido{\ik=1+1}{\lOfItemslen}{% \addlink{\lOfItems[\ik]}}%}

i.e., by taking the coordinates list as a flat list (x1,y1 x2,y2 ...), there is the following error
Runaway argument?\lOfItems [\ik ] ){\makebox (0,0){\hyperlink {p.2}{\$\rightarrow \ETC.! File endedRunaway argument?

that I could not get rid of...

migf
Posts: 11
Joined: Mon Feb 18, 2013 2:33 pm
Correction to the MWE above

A slash is missing in the argument of \setsepchars in the first definition of \addlist. The correct definition is

\newcommand{\addlist}[1]{%\setsepchar{;/,}\readlist\lOfItems{#1}%\multido{\ik=1+1}{\lOfItemslen}{% \addlink{\lOfItems[\ik,1],\lOfItems[\ik,2]}}%}

migf
Posts: 11
Joined: Mon Feb 18, 2013 2:33 pm
I have found the problem: the macros created by the listofitems package to index list elements cannot be directly used as arguments to the \addlink command in the MWE. Instead of them its \itemtomacro command must be used to obtain fully expandable macros for the elements.

\newcommand{\addlist}[1]{%\setsepchar{;/,}\readlist\lOfItems{#1}%\multido{\ik=1+1}{\lOfItemslen}{% \itemtomacro\lOfItems[\ik,1]\xcoord% \itemtomacro\lOfItems[\ik,2]\ycoord% \addlink{\xcoord,\ycoord}}%}

Hope this can be of help to others.

Stefan Kottwitz
Posts: 8598
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Great to see that it's solved! Thanks for posting the solution.

At the beginning, just seeing \put and \hyperlink with a box wasn't clear, that's why I asked for a MWE. I tested it, the problem was not easy to see, so good that you found it.

Stefan