ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Macro in a macro with optional argument
@ 2019-02-11 11:35 Pierre-Francois Bonnefoi
  2019-02-12  9:05 ` luigi scarso
  2019-02-12 16:38 ` Wolfgang Schuster
  0 siblings, 2 replies; 3+ messages in thread
From: Pierre-Francois Bonnefoi @ 2019-02-11 11:35 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Hello,

I try to define automatically some macros to include cliparts in my TikZ drawings and I've defined the following macro :

\def\clipart#1#2{% 
\expandafter\def\csname tk#1\endcsname{\dosingleempty\expandafter\csname dotk#1\endcsname}% 
\expandafter\def\csname dotk#1\endcsname[##1]{\iffirstargument\image{cisco/#1}{##1}\else\image{cisco/#1}{#2}\fi} }

\clipart{pc}{.8} % defines the macro \tkpc to include the picture "cisco/pc" 

The issue arises when I use the newly defined \tkpc : the argument is not optional and I have to put \kpc[.5] for example.
To add insult to injury, the value passed in argument is ignored also : \iffirtargument return always false...

Do you have any idea ?

Best regards,
Pierre-François.

-- 
Bonnefoi Pierre-Francois                |  E-mail : bonnefoi@unilim.fr http://p-fb.net/
Universite de Limoges, Laboratoire XLIM |       Tel : 06 28 18 03 38
123 av Albert Thomas                    |  Mrs. Peel, we're needed...
87060 Limoges CEDEX - FRANCE            |                 The Avengers.

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Macro in a macro with optional argument
  2019-02-11 11:35 Macro in a macro with optional argument Pierre-Francois Bonnefoi
@ 2019-02-12  9:05 ` luigi scarso
  2019-02-12 16:38 ` Wolfgang Schuster
  1 sibling, 0 replies; 3+ messages in thread
From: luigi scarso @ 2019-02-12  9:05 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- Attachment #1.1: Type: text/plain, Size: 1056 bytes --]

On Tue, Feb 12, 2019 at 8:27 AM Pierre-Francois Bonnefoi <
bonnefoi.pf@gmail.com> wrote:

> Hello,
>
> I try to define automatically some macros to include cliparts in my TikZ
> drawings and I've defined the following macro :
>
> \def\clipart#1#2{%
> \expandafter\def\csname tk#1\endcsname{\dosingleempty\expandafter\csname
> dotk#1\endcsname}%
> \expandafter\def\csname
> dotk#1\endcsname[##1]{\iffirstargument\image{cisco/#1}{##1}\else\image{cisco/#1}{#2}\fi}
> }
>
> \clipart{pc}{.8} % defines the macro \tkpc to include the picture
> "cisco/pc"
>
> The issue arises when I use the newly defined \tkpc : the argument is not
> optional and I have to put \kpc[.5] for example.
> To add insult to injury, the value passed in argument is ignored also :
> \iffirtargument return always false...
>
> Do you have any idea ?
>
> Best regards,
> Pierre-François.
>

could be that  \dosingleempty sees \expandafter ?
try
\expandafter\def\csname tk#1\endcsname{\dosingleempty{\expandafter\csname
dotk#1\endcsname}}%

-- 
luigi

[-- Attachment #1.2: Type: text/html, Size: 1606 bytes --]

[-- Attachment #2: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Macro in a macro with optional argument
  2019-02-11 11:35 Macro in a macro with optional argument Pierre-Francois Bonnefoi
  2019-02-12  9:05 ` luigi scarso
@ 2019-02-12 16:38 ` Wolfgang Schuster
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfgang Schuster @ 2019-02-12 16:38 UTC (permalink / raw)
  To: mailing list for ConTeXt users, Pierre-Francois Bonnefoi

Pierre-Francois Bonnefoi schrieb am 11.02.19 um 12:35:
> Hello,
> 
> I try to define automatically some macros to include cliparts in my TikZ drawings and I've defined the following macro :
> 
> \def\clipart#1#2{%
> \expandafter\def\csname tk#1\endcsname{\dosingleempty\expandafter\csname dotk#1\endcsname}%
> \expandafter\def\csname dotk#1\endcsname[##1]{\iffirstargument\image{cisco/#1}{##1}\else\image{cisco/#1}{#2}\fi} }
> 
> \clipart{pc}{.8} % defines the macro \tkpc to include the picture "cisco/pc"
> 
> The issue arises when I use the newly defined \tkpc : the argument is not optional and I have to put \kpc[.5] for example.
> To add insult to injury, the value passed in argument is ignored also : \iffirtargument return always false...
> 
> Do you have any idea ?

\define[2]\clipart
   {\setuvalue{tk#1}{\dotripleempty\doclipart[#1][#2]}}

% \def\doclipart[#1][#2][#3]%
%   {\image{cisco/#1}{\ifthirdargument#3\else#2\fi}}

\def\doclipart[#1][#2][#3]%
   {\ifthirdargument
      \image{cisco/#1}{#3}%
    \else
      \image{cisco/#1}{#2}%
    \fi}

Wolfgang

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-12 16:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-11 11:35 Macro in a macro with optional argument Pierre-Francois Bonnefoi
2019-02-12  9:05 ` luigi scarso
2019-02-12 16:38 ` Wolfgang Schuster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).