I construct a macro named \mymacro, and this macro would be used in two ways: first: \mymacro, which would typeset 1 second:\mymacro*, which would typeset 2 Here is my code: \documentclass{article} \usepackage{ifthen} \begin{document} \def\mymacro#1{\ifthenelse{\equal{#1}{*}}{2}{1}} with star: \mymacro* some text\\ % That is ok. without star: \mymacro some text % &quot;s&quot; of &quot;some&quot; lost \end{document}   From the attached typeset you can see that the first charactor s of the word some is lost in the version of without star. Why? I know \mymacro{} is a solution, but I'd like to know if there is a better way to just use \mymacro only.
45981
I would like to define a *'d version of a command, something like \newcommand{\foo}{blah} \newcommand{\foo*}{blahblah}  If I try to do this, LaTeX complains that I'm trying to redefine \foo, so I guess I need to do something special to handle *s. But what?
110647
I have the following:  \newcommand{\makeWord}[1]{% \newcommand{\#1}{\textrm{#1}}}  \makeWord{AdditiveGroup} \newcommand{\AdditiveGroup}{\textrm{AdditiveGroup}}   Unfortunately, I did not properly define the makeWord macro. How do I fix this?
89843
I am preparing a LaTeX beamer presentation for students. I am looking for a simple way to create two versions of my presentation.  One version for the Students, which just contains the text of the tasks they get for homework and an other one for me which also contains the solution.  So I have created a macro that is intended to check if the file name contains "student". If it does, the macro outputs nothing, and if it does not, the argument is passed:  \newcommand{\hausaufgabenLoesung}[1]{%     \IfSubStringInString{student}{\jobname}{}{#1}% }   But this does not work as intended. No matter how I name the file, the conditional always goes to the false-expression. I think the \jobname macro returns something which can not be processed by \IfSubStringInString but I have no other idea how I could approach this.  If I replace the \jobname macro in the conditional with a fixed string, it works as intended but this would render it fairly useless.  I used \jobname to avoid including the currfile-package, but with the currfile-macros I get the same behaviour. I am using texlive 2014 pdflatex on Linux and Windows.  Anyone here got a hint for that?  Here is a minimal complete example:  \documentclass[ngerman]{beamer}  \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[ngerman]{babel}  \usepackage{ifthen} \usepackage{substr}  \newcommand{\hausaufgabenLoesung}[1]{%     \IfSubStringInString{student}{\jobname}{}{#1}% }  \begin{document}  \begin{frame}{Title}{Subtitle}     \begin{itemize}         \item \jobname         \item Visible in both files         \hausaufgabenLoesung{\item Solution not in the student file}     \end{itemize} \end{frame}  \end{document}
66487
I am preparing some lecture notes/slides and would like to efficiently create two versions of the output: a complete version for myself, and a version for my students with certain text replaced with blanks or an empty box so that they can fill it in during lectures.  the \underline{\phantom{text}} command does the trick, but it would be time consuming to create a separate version of the document and insert this in all the relevant places.  How can one use macros to give us the ability to easily toggle between the teacher version (with full text) and student version (with blanks)?  I was going to post this as a question but then figured it out so thought I'd share it.
21853
I wrote the following code to typeset the title page of a paper:  \documentclass{amsart}  \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[USenglish]{babel}  \begin{document}  \title[Title Title Title]{Title Title Title}  \begin{abstract}     Abstract abstract abstract \end{abstract}  \maketitle  \end{document}   This outputs the following:    However, I wanted to make my title a macro, because I need it elsewhere too:  \documentclass{amsart}  \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[USenglish]{babel}  \newcommand\mytitle{Title title title}  \begin{document}  \title[\mytitle]{\mytitle}  \begin{abstract}     Abstract abstract abstract \end{abstract}  \maketitle  \end{document}   But this now outputs the following:    No way of fiddling got me the capitalization back. E.g. there is no difference in using \def. What is happening here and how to fix it?
76424
In  I ended up with  \DeclareMathSymbol{:}{\mathpunct}{operators}{"3A}   But now I'm using the fontspec package which redefines : with \AtBeginDocument itself. So as my own definition comes before fontspec is loaded, even putting it in \AtBeginDocument won't help.  Is there a way to say “Execute this after fontspec has loaded!” or “Execute this at the very end of \AtBeginDocument!”?
111544
I defined a question macro, then made it successively fancier.  Right now, three macro should define a short hand for the following:  \section{Questions} \begin{enumerate} \item Q1... \item Q2... \end{enumerate} \section{Exercises} \begin{enumerate} \item exercise 1 \item exercise 2 \end{enumerate} \href{my.url.goes/here/specific}{Take the quiz}   The three commands defined to do this are:  \newcommand{\qqq}{\section{Question}\begin{enumerate}} \newcommand{\exer}{\end{enumerate}\section{Exercises}\begin{enumerate}} \newcommand{\endexer}[1]{\end{enumerate}\href{my.url.com/path/{#1}}{Take the quiz}}   A sample call to make this happen:  \qqq \item What is 2+3? \exer \item Write a program to compute 2+3 \endexer{123}   should generate the url:  my.url.com/path/123  The error is:  ! LaTeX Error: Command \endexer already defined.                   Or name \end... illegal, see p.192 of the manual.  I am not posting the MWE because I think this is a stupid syntax error based on something I am missing about \newcommand, but if I'm wrong, I will create an MWE and add it here.
5240
As mentioned in many of my previous questions, I'm working through K&amp;R, and am currently into the preprocessor. One of the more interesting things &mdash; something I never knew before from any of my prior attempts to learn C &mdash; is the ## preprocessor operator. According to K&amp;R:     The preprocessor operator ##   provides a way to concatenate actual   arguments during macro expansion. If a   parameter in the replacement text is   adjacent to a ##, the parameter is   replaced by the actual argument, the   ## and surrounding white space are   removed, and the result is re-scanned.   For example, the macro paste   concatenates its two arguments:      #define  paste(front, back)  front ## back      so paste(name, 1) creates the token   name1.   How and why would someone use this in the real world? What are practical examples of its use, and are there gotchas to consider?
106113
\section* produces an unnumbered section, align* , which is comparable in a way. \newcommand* , which is different.  Stefan Kottwitz :     Commonly, a star symbol * means a version of a command that behaves differently from the original. That often means suppressing numbering but could also refer to special features.   This might answer my question, but perhaps there's more to say (and it's nice to have it as a separate question).  Is there anything all starred commands have in common? Why would one define a starred command as opposed to another, differently named command indicating their semantic difference in the names? It seems that their definitions are usually entirely independent from each other.  Further reading:
63171
Writing "C++" in plain text results in an ugly setting, as the '+' signs are too big and too spaced:    I've seen around the web several marcos for typesetting the "C++" symbol, ranging from mild kerning to shrinking, raising and lowering the '+' signs.  What is your version of a \cpp{} macro?
43165
Both uses of the \let primitive often lead to the same result. Is this even true for every case? What was the thought process behind it. And if they are actually not equivalent, are there particular situations in which you can only use one or the other?  Addendum  Summary  As your plenty and nice answers show, there are cases in which you clearly have to respect one of the variations (for instance regarding assignments to '=' and macros that check for spaces). These were totally understandable points and they explain a lot. Now, @Werner's answer confirmed one ingenuous thought of mine:     "The use of = is purely to emphasize the fact that an assignment is being made [...]"   Moreover Knuth himself seem to have intended the synopsis including the '=', though he also used the other way. Why did he include it then? It will probabilly have to do with the exact meaning of the TeX source snippet cited by @Werner. To be honest, I don't know WEB either, but if there is someone who does, can he explain it (in very easy terms) by adding an edit to his answer? New answers are clearly welcome too.  Side Note  As an element of a gray area I found an example where using the syntax including the equal sign causes "difficulties":  If you have control sequences which need the 'csname-expandafter' mechanism, and you want to stick to the minimal exploitation of \expandafter by saying  \expandafter\let\csname foo1\expandafter\endcsname\csname bar1\endcsname   you can't add an equal sign because it would distract TeX from reading the \expandafters correctly. To get the equal sign work you would need to use the slightly unhandier version  \expandafter\let\csname foo1\expandafter\endcsname\expandafter=\csname bar1\endcsname
27115
Consider the following example of a patch using  and a dummy macro \abc:    \documentclass{article} \usepackage{etoolbox}% http://ctan.org/pkg/etoolbox \newcommand{\abc}[2]{#1\ #2}% Magic macro \begin{document} \abc{A}{B}  % \patchcmd{&lt;cmd&gt;}{&lt;search&gt;}{&lt;replace&gt;}{&lt;success&gt;}{&lt;failure&gt;} \patchcmd{\abc}{#1}{#2}{}{}% \abc{A}{B} \end{document}   If I want to maintain good programming practice, I'm encouraged to put \patchcmd in the document preamble (separating structure from content) and only trigger it with a different macro, say \patchabc:  \documentclass{article} \usepackage{etoolbox}% http://ctan.org/pkg/etoolbox \newcommand{\abc}[2]{#1\ #2}% Magic macro \newcommand{\patchabc}{%   % \patchcmd{&lt;cmd&gt;}{&lt;search&gt;}{&lt;replace&gt;}{&lt;success&gt;}{&lt;failure&gt;}   \patchcmd{\abc}{#1}{#2}{}{}% } \begin{document} \abc{A}{B}  \patchabc% Patch \abc \abc{A}{B} \end{document}   However, the above does not work since #1 and #2 inside \patchabc is assumed to reference its arguments while \patchabc has none. How can I write a macro that acts like a switch (and is cleaner in terms of the programming) that patches another macro's use of its own arguments?
41583
I accidentally, discovered that using | in text mode produces an em dash. I did a quick search, but I could not find a reference where this is noted. I wonder if there is any difference between this and ---? Otherwise, it seems easier to just type one character instead of three.
53661
I've made a mymacros.sty file which I would like my LaTeX files to be able to access with commands that I've defined. I've managed to get it to work by putting \usepackage{mymacros} in my preamble.   However when I try to autocomplete I can't. I looked at this question:     ), which recommends 3 ways of doing this, none of which work for me.    The first it recommends is to have mymacros.sty open in the editor. But this doesn't work.  The second is to activate the option Editor -> Automatically load included files in the configure TeXstudio options panel. However while I have an Editor tab , there is no such option there.  The third is to using .cwl files, however I'm not sure how to go about this. In the completion tab I've noticed that there is a mymacros.sty option that has come up, which I ticked but that has had no effect. Do I need to make my own mymacros.cwl file? I've tried to look this up but haven't had any luck.  Anyone have any ideas? Thanks in advance!
26731
I tend to use \newcommand to define macros for symbols I use often, e.g. \newcommand{\hankel}{H^{(1)}_0}.  One inconvenience of this approach is the fact that command names cannot include numbers.  What I ideally want is to map something like \H0 to H^{(1)}_0.  I imagine this could be done with some macro expansion/snippet package, or one might use \newcommand to define a command that takes a parameter, etc.  Before I start experimenting, though -- is there a canonical way of dealing with this problem?
92291
How is it possible to use the end-of-line character as a macro parameter ? I would like something along the lines of :  \def\mymacro#1\endlinechar{Content:#1} \mymacro First content \mymacro Second content   Giving the following output :  Content: First content Content: Second content   I have tried \endlinechar and \^^M but it does not work that easily.
63497
ConTeXt has a .mkvi file extension for modules (roughly similar to LaTeX packages) which allows to use named arguments like: \def\foo[#parameters]#content{ #parameters ... #content ...}  instead of \def\foo[#1]#2{#1 ... #2 ...}  Not really a difference, but it has an advantage that macros tend to be more readable. Are there any packages or functionalities which allow the same for LaTeX?