This is what I want to do:  \newcommand{\foobar}[n]{%   \hspace*{1.5ex}-\hspace{1ex}\emph{#n}\\% }   And then use it like this:  \foobar   {Hello}   {World}   However this doesnt actually work. I want   \hspace*{1.5ex}-\hspace{1ex}\emph{#n}\\%   To appear for as many arguments as I supply to \foobar. How do I do this?  NOTE  To clarify, what I want finally is this:  - Hello - World - N number of other arguments
60659
I have a situation where I want to define a command that takes a variable number of arguments, where the number of arguments is known programmatically via a \count, and process the parameters in some way (say as if they are a list).  As an example, say I'd like to output the parameters as a comma-separated list.  \newcommand{\makecsv}[N]{#1, #2, ..., #N}   The code that I've come up with to do this kind of operation (in a generic-ish way) essentially takes a command, \csv and expands it recursively N times. \csv needs to know how to continue the recursion, and has some state that I'd like to thread through the recursion (rather than using \global).  \documentclass{report} \usepackage{etoolbox}  \makeatletter \newcommand{\ifzero}[3]{%   % #1: count   % #2: state for #3   % #3: macro to expand to   % - should take at least 2 parameters   % - ##1: count threaded through   % - ##2: macro state threaded through   \ifnum\c &gt; 0     \def\tmp@f##1##2##3{##1{##2}{##3}}%     \advance#1 -1%   \else     \def\tmp@f##1##2##3{)}% note closeparen here (could be param)   \fi   \tmp@f{#3}{#1}{#2}% } \makeatother  \newcommand{\csv}[3]{   % #1: count   % #2: separator state   % #3: string to concat   %    #2#3\ifzero{#1}{, }{\csv}% }  \newcommand{\makecsv}[1]{%   \ifzero{#1}{}{\csv}% }  \makeatletter \newcommand{\decl}[3]{%   % #1: decl id   % #2: decl symbol   % #3: # params   \csgdef{decl@#1}{#2}%   \global\expandafter\newcount\csname decl@#1@nparams\endcsname%   \csuse{decl@#1@nparams} #3\relax% }  \newcommand{\usedecl}[1]{%   \newcount\c   \c \the\csuse{decl@#1@nparams}   \csuse{decl@#1}(\makecsv{\c}% } \makeatother  % declare some interface routines \decl{foo}{FOO}{3} \decl{bar}{BAR}{4}  \begin{document} \usedecl{foo}{p1}{p2}{p3}\par \usedecl{bar}{p1}{p2}{p3}{p4}\par \end{document}   Is this a reasonable thing to do in 2e, or is there some sort of standard approach to this that is normally used?  Edit 1  It seems like my original MWE wasn't adequate to describe why someone might want this. I've updated the MWE with a use case. \decl allows authors to declaratively define a C-style function, and \usedecl allows the author to generate a use of the function, with its parameters bound to specific arguments.  This is similar enough to what I'm doing that it should help motivate the example.
73407
How can I define my own shorthand command, but making sure that the spacing afterwards is correct?  \newcommand{\abc}{\textsc{abc}} produces 'ABC,' but has the problem 'ABCmoretexthere' (i.e. no space before the next word).  Vice versa  \newcommand{\abc}{\textsc{abc} } produces  'ABC moretexthere' but has the problem 'ABC ,' (i.e. one space before the comma).  How can I make both work?
21438
In  we learned how to use \newcommand within a command definition with another \newcommand, when the name of the inner command needs to contain a parameter of the outer command. Now, suppose I want to do the same, but for the inner \newcommand to also have parameters, i.e. I want the following code to work:  \newcommand{\defsilly}[1]{%   % define a command named silly#1 , taking a single parameter } \defsilly{willy} \sillywilly{theparameter}   Motivation: I'm writing a thesis document class, which has a bunch of the following kind of command pairs:  \newcommand{\iitthesis@authorEnglish}{Name of Author} \newcommand{\authorEnglish}[1]{\renewcommand{\iitthesis@authorEnglish}{#1}}   I want to replace each of these pairs with something like:  \iitthesis@thesisdatafield{authorEnglish}{Name of Author}   This defines both the above commands.
54017
I am trying to define a command that takes two arguments, where one is optional. If the optional argument isn't given I would like the compulsory argument to be used for the optional argument.  For example:  \necommand{\foo}[2][#2]{#1 foo(#2)}   which would return:  IN: \foo[hello]{hi}      OUT: hello foo(hi) IN: \foo{hi}             OUT: hi foo(hi)   Ideally it would be nice to keep it simple and use standard LaTeX with no packages. Thanks in advance!
79894
Can you explain what this command does:  files=(this_is_filename) for filename in ${files[@]}; do    ls -t1 ../htory/$filename* |     head -1 |     xargs -I fname cp -p fname ../htory2/somefile.CSV done   Especially this part of this command  xargs -I fname cp -p fname ../htory2/somefile.CSV
48516
I want to transform /foo/bar/.. to /foo  Is there a bash command which does this?    Edit: in my practical case, the directory does exist.
123851
I am trying to create a command to modify fontsize with one parameter, it seems that the paramater is not expanding properly:  \newcommand{\mycfs}[1]{\fontsize{#1pt}{1.2*#1pt}}
55549
I usually go to stackexchange when I face programming terminal and I spend most of time trying to append four spaces before my pasted programming code.  Is there any faster way to do it from a terminal? What would you do?
11190
When building console applications that take parameters, you can use the arguments passed to Main(string[] args).   In the past I've simply indexed/looped that array and done a few regular expressions to extract the values. However, when the commands get more complicated, the parsing can get pretty ugly.    So I'm interested in:   Libraries that you use Patterns that you use   Assume the commands always adhere to common standards such as .
89074
It seems that a common operation needed when defining new commands is to scan over a list of arguments (separated e.g. by a comma, but maybe by something else) and do something with each argument in the list, find the last one, or whatever.  For example to write commands that look like \Command{a,b,c} or \Command{c.d.e} and do something with each a, b, and c. See e.g. questions on  and .  Some solutions have been posted there, but what would be the best idiom to perform such kind of operations? LaTeX's \@for looks very nice, but is it possible to use it to scan anything other than comma-separated lists?
99452
I'm quite happy hacking TeX macros and cobbling together bits and pieces from different style files to suit my own ends, but I have a suspicion that my resulting hacks are not quite as elegant as they could be.  In particular, with regard to when to expand and when not to expand macros.  A common occurrence for me is defining a meta-command that defines a whole slew of sub-commands.  So the names of the sub-commands will contain parameters depending on the parameter passed to the meta-command, and the contents of the sub-commands will also vary a little depending on what the meta-command got.  Often it won't be a direct substitution but rather a "if #1 is a do \this else do \that", but \this and \that need expansion at define time, not call time.  Here's a very simple example just involving direct substitution:  \def\cohtheory#1{ \expandafter\newcommand\expandafter{\csname #1func\endcsname}[1][*]{% \MakeUppercase{#1}^{##1}} }   Sometimes I worry that my commands are more complicated than they need be.  For example, if I want to call a command with two arguments and the arguments expand before the command, here's how I've coded it:  \expandafter   \expandafter   \expandafter   \command\expandafter             \expandafter             \expandafter               {\expandafter                 \argone                 \expandafter               }\expandafter               {\argtwo}   So I'm looking for guidance on when and how to control expansion in defining macros.  I strongly suspect that such cannot be given in a simple answer, so to make this a focussed question, let me phrase it thus:     Where's a good reference for writing TeX macros that includes advice on how to best deal with how to handle expansions?   Of course, if anyone can formulate some advice in short answer, I'd be only to happy to read it.  (Note: this was partially motivated by juannavarroperez's adaptation of my answer to  where over 20 \expandafters got condensed down to just 1!)
31700
After you define a command using \newcommand, is it possible to undefine it?  My motivation is that I'm writing a thesis, where each chapter is in a separate source file. Some chapters define their own commands that are used nowhere else, so I'd like them to be visible only within that chapter.   I'd therefore like to be able to do something like:  \chapter{Some Chapter} \newcommand{foo}{...} ... % chapter body \forgetcommand{foo} % end of chapter   Is there anything like the fictitious \forgetcommand macro above?
59057
I want to define a command \filepath so that I can use \filepath{foo_bar.cpp} and it is printed in monospaced font.  Also, why does this not work? I get strange errors:  \newcommand{\filepath}[1]{\verb!#1!}
104419
I have a script myscript.sh  #!/bin/sh  echo $1 $2   which is used something like ...  ./myscript.sh foo bar   which gives me an output of ...  foo bar     but how can i make this script include custom command options? for example ...  ./myscript.sh -a foo and corespond to $1   and  ./myscript.sh -b bar and corespond to $2
41046
This is a follow-up question to , but I am afraid it is of a different nature now. The accepted answer seems to put unwanted spaces after the custom-defined environments. I am not sure how to remove them and what is causing them exactly. Apologies if this question is a bit vague as I absolutely have no idea.  Here is a MWE.  \documentclass[a4paper,leqno]{amsart} \usepackage{amsmath, xparse,xspace} \setlength{\parindent}{0pt}  \makeatletter \newcommand{\eqnum}{\textup{\tagform@{\theequation}}} \makeatother  %%%%% \ExplSyntaxOn  \NewDocumentEnvironment{aligncol}{m+b}{\guissmo_aligncol:nn {#1} {#2}}{} \NewDocumentEnvironment{aligncola}{m+b}{\guissmo_aligncol:nn {#1} {#2}}{a}  \seq_new:N \l__guissmo_aligncol_in_seq \seq_new:N \l__guissmo_aligncol_out_seq \seq_new:N \l__guissmo_aligncol_temp_seq \int_new:N \l__guissmo_aligncol_rows_int  \cs_new_protected:Nn\guissmo_aligncol:nn { %storetherowsinthesequence \seq_set_split:Nnn\l__guissmo_aligncol_in_seq{\\}{#2} \int_compare:nF{\int_mod:nn{\seq_count:N\l__guissmo_aligncol_in_seq}{#1}=0} {%numberofrowsnotamultipleof#1,addemptyentries \prg_replicate:nn{#1-\int_mod:nn{\seq_count:N\l__guissmo_aligncol_in_seq}{#1}} { \seq_put_right:Nn\l__guissmo_aligncol_in_seq{} } } \seq_clear:N\l__guissmo_aligncol_out_seq \int_set:Nn\l__guissmo_aligncol_rows_int {\int_div_truncate:nn{\seq_count:N\l__guissmo_aligncol_in_seq}{#1}} \int_step_inline:nn{\l__guissmo_aligncol_rows_int} {%clearthetemporarysequence \seq_clear:N\l__guissmo_aligncol_temp_seq \int_step_inline:nnn{0}{#1-1} { \seq_put_right:Nx\l__guissmo_aligncol_temp_seq { \seq_item:Nn\l__guissmo_aligncol_in_seq {##1+\l__guissmo_aligncol_rows_int*####1} } } \seq_put_right:Nx\l__guissmo_aligncol_out_seq { \seq_use:Nn\l__guissmo_aligncol_temp_seq{&amp;} } } %now\l__guissmo_aligncol_out_seqcontainsthenewrows \begin{equation}\eqnum \begin{minipage}{0.9\textwidth} \setlength{\abovedisplayskip}{0pt} \setlength{\belowdisplayskip}{0pt} \setlength{\abovedisplayshortskip}{0pt} \setlength{\belowdisplayshortskip}{0pt} \setbox0=\hbox{T}%tallestletterofthefirstlineofotherminipage \vskip-\ht0 \begin{align*} \seq_use:Nn\l__guissmo_aligncol_out_seq{\\} \end{align*} \end{minipage} \end{equation} } \ExplSyntaxOff  \begin{document}  Hello! \begin{aligncol}{1} a &amp;= a \end{aligncol} This has an extra space at the beginning. I don't want it. \\ This does not not. \begin{aligncol}{1} a &amp;= a \end{aligncol}This does NOT have an extra space, but the code is ugly. \\ This one does NOT have extra space too! \begin{aligncola}{1} a &amp;= a \end{aligncola} It seems that the space comes after the environment definition. \\ Is it the indeed case?  \end{document}   Here is a screenshot of the output.
68466
I have a very simple question. When I do this:  \catcode`\@=0 \catcode`\\=11 @mycommand{a} @catcode`@\=0 \catcode`\@=11   It works perfectly and calls \mycommand correctly. However, when I try to define \mycommand with similar trickery:  \newcommand\mycommand[1]{   \catcode`\@=0   \catcode`\\=11   @textbf{Hello #1}   @catcode`@\=0   \catcode`\@=11 }   compilation stalls and gives me the * prompt. If I give it Ctrl+D, it terminates without producing any output. Indeed, it seems that changing the catcodes inside a command has no effect whatsoever, because the following works perfectly (whereas, from my understanding, it shouldn't):  \newcommand\mycommand[1]{   \catcode`\@=0   \catcode`\\=11   \textbf{Hello #1} }   Can anybody please explain to me what's happening?
120097
I am trying to create a macro that creates two macros. The first sets a default value and the second creates a macro to redefine the first. I am trying to generalize a common pattern I am using quite a bit.  \newcommand{\mkMac}[1]{% \newcommand{\the#1}{The macro ##1} \newcommand{\#1}[1]{\renewcommand{\the#1}{##1}} }   Usage:  \mkMac{affilation} \affilation{University} Welcome to \theaffilation