I'm using \newcommand for create some custom functions in my text. Some of these functions have 2 or 3 arguments and many times I confuse the input order.  The default commands of LaTeX in my TeXstudio editor shows suggestions like      But the new commands does not do it, only shows arg1 and arg2  \documentclass[12pt,a4paper]{article} \usepackage{blindtext} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}  \newcommand{\test}[2]{#2 and then #1}  \begin{document}  \test{second}{first}  \test{arg1}{arg2}  \textbf{text}  \end{document}       There is a way to change the words arg1 and arg2 for second and first for example?  \test{second}{first} instead \test{arg1}{arg2}
123671
How to name the arguments in \newcommand so that when you call the macro they don't appear as {arg1}{arg2}... etc. but with the names each argument represent {caption}{label}... etc. without the use of a .cwl file.  I'm trying to implement the following \newcommand  \documentclass{article}  \usepackage{ctable} \usepackage{mwe}  \newcommand{\qfigure}[5]{\ctable[ caption= {#1},label= fig:#2,figure, pos=H,botcap, mincapwidth= #3 mm]{c} {}{\includegraphics[width=#4\textwidth]{#5}}}  \begin{document}  % \qfigure{arg1}{arg2}{arg3}{arg4}{arg5} % They would appear like this in Texstudio \qfigure{An image example}{test}{70}{0.5}{example-image-a}  \end{document}   As you can see there are five arguments where each one represents the caption, label, min width of caption (ctable parameter), width and file name respectively.  Thanks in advance for any help.
9215
LaTeX seems to be having problems handling nested optional arguments. I've included a minimal code example that generates the error:  \documentclass[12pt,oneside]{book} \begin{document}  \newcommand{\termbad}[2][]{#2#1} \newcommand{\termgood}[2][]{#2#1}  \newcommand{\up}[1]{#1} \newcommand{\dd}[1][]{#1}  \termgood{\up{Tart}}{Pop} \termbad[\up{Tart}]{Pop}      \termgood{\dd[Tart]}{Pop} \termbad[{\dd[Tart]}]{Pop} %\termbad[\dd[Tart]]{Pop}   \end{document}   If you run this code, it works. If you remove the % in the second to last line, it fails with:  Runaway argument?  Tart{Pop} \par \par \end {document}  !File ended while scanning use of \dd.   After further tinkering, I have discovered the problem: LaTeX is reading the ] for the inner optional argument as the end of the outer optional argument and then passing a malformed argument in. So it is passing in \dd[Tart as the optional argument to \termbad instead of \dd[Tart].  This still feels like a bug to me. Nesting braces in arguments works, brackets should as well. The following are workarounds:   Enclose the inner optional argument in braces (as in the line before %). Redefine your inner function to require its argument instead of using optional arguments. Redefine your outer function to require its argument instead of using optional arguments.   Any one of the three works around the issue.  (Reposted here; question was originally posted to stackexchange and then closed instead of being migrated.)
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?
32826
Are there compelling reasons to stick with \newcommand or should one always use \NewDocumentCommand instead, even when not using any of the additional features offered by xparse?  In addition and more specifically,   If I already require xparse to define one of the macros of my document/package/class, is it a good idea to use \NewDocumentCommand for all my other macro definitions? Will \newcommand eventually get deprecated/discouraged in favor of \NewDocumentCommand with LaTeX3?
8040
I'm trying to construct a command with one optional and one mandatory argument and I'd like the default if the optional argument is not provided to be #2.   Why does this not work?  (error: Illegal parameter number ...)  \documentclass{article}  \newcommand{\mycommand}[2][#2]{\label{#1}#2} \begin{document} \mycommand{mytext} \end{document}   And what would be a way around it?   EDIT: For clarification of my specific use case: I'm trying to define a command that passes a variable on as an option to an environment along those lines, where myenv can have options like optionone=X or optiontwo=Y so the default for the optional #1 should be optionone=#2 (not literally #2).   \newcommand{\mycommand}[2][optionone=#2]{\begin{myenv}[#1]\input{#2}\end{myenv}}   Maybe there's generally a better approach?   (The environment definition I'm using is from .)
6746
Many LaTeX “hacks” begin with \makeatletter and end with \makeatother. What do these commands do?
94851
I want to set up a macro in TeXstudio for math mode which displays $*$ and places the cursor at position *. So far I have tried using $%|$ but upon triggering, this macro does not allow text insertion at the placeholder.  EDIT: The method above works fine if the macro shortcut is set to the default Shift+F1. However, changing the shortcut to another combination, as I would like to do, seems to be the cause of the problem.
44041
I am new to Vim. I'm following  tutorials to help me learn to use it.  But some of my commands are not working, for example:  Capital W. f followed by a character. (To move to next same char.)   Why is this happening and how can I get these commands to work?
42336
After reading another question relating to how to see definitions of commands, I tried:  \documentclass{article} \begin{document} \show\LaTeX \end{document}   But this shows me in my logfile:  \LaTeX=macro: \protect \LaTeX   I just want to see where the \LaTeX command deep down somewhere finally says "OK, make the 'L' big, then make a little raised 'a,' then ..."
28876
I'm trying to define two commands \bal and \eal instead of inserting \begin{align} and \end{align} in my document, but in the code below, I'll get some errors. What is wrong with it?    \documentclass{article} \usepackage{amsmath} \makeatletter  \newcommand{\bal}{%  \begingroup  \align% \@ifstar{\nonumber}{}%  }  \newcommand{\eal}{\endalign\endgroup} \makeatother \begin{document} \bal* x=y \eal ‎\end{document}
46706
With newcommand I can define customized command like \ABC. Is there any way to define a command with arguments. For example I want \brat{A}{B} be the same as [\![A,B]\!].
86513
In order to separate the content structure from the style, I decided to implement commands for denoting random variables:  \newcommand{\myrv}[1]{\mathbf{#1}} \newcommand{\rvA}{\myrv{A}} \newcommand{\rvB}{\myrv{B}} \newcommand{\rvC}{\myrv{C}} ...   This way, if I ever decide to change the style of random variables from \mathbf to say \mathbb, all I need to do is to change the definition of \myrv. Is a way to generate the commands \rvA, \rvB, \rvC, ... automatically?
18456
I am doing my first LaTeX work using TeXstudios and I'm having trouble with an Undefined control sequence.   When I've checked solutions on google it appears as this is caused by typos in the different commands.  However, I have used the TeXstudios implemented menus to generate the codes so it shouldn't be any problem with that.  The code I'm having trouble with is  $x\in\mathbb{R}^{n}$   which I intend to become x belonging to the real numbers with n as an exponent.   I get the error   Undefined control sequence $x\in\mathbb
15897
Why is the following minimal example not working?  I.e., what do I need to do, in order to define the float placement specifier of a figure within a macro? (I know that I should use \newcommand, but in the "full" example the error is part of an involved "superfigure" command. \newcommand is not working too btw.)  \documentclass{scrreprt} \usepackage{blindtext}  \def\PosNotWorking{h} \def\FramboxNotWorking{5cm} \def\CaptionWorking{Caption is working.}  \begin{document}  \Blindtext[1]  \begin{figure}[\PosNotWorking]   \centering     \framebox[5cm]{My special figure. (Pos: \PosNotWorking)}             \caption{\CaptionWorking} \end{figure}  \Blindtext[1]  \end{document}   If I compile this, the figure is at the top (default behaviour). If I enter \figure[h] instead of \figure[\PosNotWorking], the figure is of course between the two paragraphs.
20269
This is not about new macros like \newcommand, \def and others. This is not about autocompletion like using .cwl (in TexStudio) This is also not about using shortcuts for predefined commands that are listed in the shortcuts sections.   It is more closely related to the 3. Though. I want to define shortcuts for commands that are not listed there.  e.g. When I type Ctrl + Shift + B, I want   \begin{bmatrix} \end{bmatrix}   to be inserted just like Ctrl+ Enter inserts \\.
63157
This isn't a real question, so I'm marking it community wiki.  When I was new to LaTeX, I thought that the \usepackage command worked much like the #include command of the C language: just put whatever you need in the preamble, in whatever order you like.  But then bugs began to bite me and I realised, with growing horror, that commutative packages seem to be the exception rather than the rule.    so  that I think it would be useful to have a list here of problematic interactions between pairs of packages, and their correct order.  Also, a question for amusement:   I want to know if there exists three packages A, B and C, such that A has to be included before B and B needs to be included before C, but C needs to be included before A.
20492
Mathematical operators, such as function names, should be set in roman type, not italics. Latex already has commands for some operators, including \max, \min, and \log.  How can I define additional such commands?