The Stack Overflow podcast is back! Listen to an interview with our new CEO.

# Tag Info

2


1

You can do it with the powerful methods of expl3. The body is split at \\, then the header row is separated off; we just need to take care about a trailing \\, that would produce an empty row, so we check that (see comments in the code). The tjttabular environment has an optional argument, default 3; if you type \begin{tjttabular}[4], you'll get a four ...

6

It’s not clear what you want to do when you explicitly reset the math style. The following solution, which requires amsmath but works also with the “classical” typesetting engines, discriminates based on the \if@display switch. This purposely ignores the math style (\displaystyle vs. other styles), and decides which command to use (\varprojlim vs. \lim) ...

13

Since you are using LuaTeX, you can simply query \mathstyle. \documentclass{article} \usepackage{amsmath} \usepackage{unicode-math} \newcommand\catlim{% \ifcase\mathstyle % 0 = \displaystyle \expandafter\varprojlim \or % 1 = \crampeddisplaystyle \expandafter\varprojlim \else % all other styles \...

5

Here's an implementation with xparse and expl3. The idea is to first sum the items in the “multiratio” so as to establish the modulus. Then a suitable preamble is built, multiplying each item by the modulus and subtracting twice the \tabcolsep. I set up things so you don't need to type \hline. The optional argument defaults to \columnwidth, but you can ...

3

The following uses tabularx and its X-type column (though this won't be necessary). It works in a similar manner as @Werner's answer in that it sums the ratios and then uses the entries of the sequence again to set the widths of each column. It adds a \hline before and after the contents of your table. \documentclass[]{article} \usepackage{xparse} \...

2

The following version of \quicktable{<colspec ratio>}{<table>} processes the first argument - <colspec ratio> - twice. The first time it adds up the "ratios" into some total. During the second run it specifies the column width of each column as a ratio of \linewidth (minus the dual column padding provided by \tabcolsep). Finally, it sets ...

2

You need to expand \thethought: the footnote text is expanded right away, so there is no problem with it, but \endnote just saves the text without interpreting it. \documentclass{article} \usepackage{endnotes} \newcounter{thought} \newcommand\mythought{% \refstepcounter{thought}% \noindent \textbf{Thought \#\thethought:}% } %-> Defining the ...

6

It is possible to define the command so that braces are not needed by relying on the low level detail that _ scans for an argument in a way that is not at all like the scanning for a macro argument, so you just need a \bgroup before looking for the optional argument: \documentclass[pdftex,11pt]{report} \usepackage{xparse} \NewDocumentCommand\MyCmd{}{\...

0

Based on the link provided barbara beeton: How to avoid using curly braces when placing a \DeclareMathOperator command in subscript or superscript, while preserving spacing? Double subscript error with \newcommand? in my case the answer would be: There is no such way to avoid using braces. On the other hand, it is a good "coding" practice to always ...

3

One of TeX's core features, delimited arguments/parameters, doesn't seem to be widely used in LaTeX user code, so some of the common idioms related to them may not be immediately clear when you encounter them in package code. The syntax and argument reading for those parameters is explained in this answer, so I'd like to concentrate on some examples of more ...

4


0

You can also use the xspace package (Insert a space after a command: {}, vs \ , vs \space): \usepackage{xspace} % <month> <year> <month> <year> \newcommand{\timeperiod}[4] {% #1\xspace#2\xspace--\xspace#3\xspace#4% } But do not forget about Drawbacks of xspace

2

You can reimplement the counting in \glossthis: \documentclass{article} \usepackage{xparse} \usepackage{expl3} \usepackage{lingmacros} \ExplSyntaxOn \newcommand{\glossthis}[3]{% \seq_set_split:Nnn \l_tmpa_seq {&} {#1} \shortex{\seq_count:N \l_tmpa_seq}{#1}{#2}{#3} } \ExplSyntaxOff \begin{document} \enumsentence{\glossthis% {?& \.{I}ki &...

11

Just slightly modifying your code: \documentclass{article} \usepackage{ifmtarg} \usepackage{siunitx} \sisetup{number-unit-separator=\,} \makeatletter \newcommand{\sitime}[1]{\sitime@aux#1;;;\@nil} \def\sitime@aux#1;#2;#3;#4\@nil{% \@ifmtarg{#1#2#3}% {% \PackageError{siunitx (modified)}% {...

7

You can have a friendly syntax: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\hms}{ >{\SplitArgument{2}{;}}m } { \ensuremath{\andrec_hms:nnn #1} } \cs_new_protected:Nn \andrec_hms:nnn { \group_begin: \bool_set_false:N \l__andrec_hms_thinspace_bool \__andrec_hms_print:nn { 0#1 } { h } \tl_if_novalue:nTF { #...

4

Make copies of both \Aboxed and \@Aboxed. Edit the copied versions. \documentclass{article} \usepackage{mathtools,tcolorbox} \makeatletter \let\Asol\Aboxed \let\@Asol\@Aboxed \patchcmd{\Asol}{\@Aboxed}{\@Asol}{}{}% \patchcmd{\@Asol}{\boxed{#1#2}}{\fcolorbox{red}{yellow}{$\displaystyle #1#2$}}{}{}% \makeatother \begin{document} \begin{align*} \Aboxed{n+1 ...

0

The limitation here is the use of \textcolor{color}{text} it can only handle up to a single paragraphs worth of text. Simpler method: \newcommand\todo[1]{{\color{red}TODO: }} Here the extra {} acts as a group such that the color does not escape. I would though, take a look at todonotes or fixme instead of doing too many homemade solutions. Fixme can be ...

0

As @daleif has said in comments, the problem is that \textcolor does not allow \par in its argument. Internally, the macro is defined as: \def\textcolor#1#{\@textcolor{#1}} \def\@textcolor#1#2#3{\protect\leavevmode{\color#1{#2}#3}} If \@textcolor would have been defined as \long, you should not have this problem. So you could, in principle redefine this ...

4

Here is an alternative version that checks if the code following the first parameter starts with an opening brace {. If so it treats it as a second argument, otherwise it assumes only one argument is given. However, as this makes the code less readable and maintainable, I do not really recommend its usage. The implementation uses \@ifnextchar to test for ...

5

Optional arguments are usually set first and specified in brackets [] rather than braces {}. With your code, if you type $\comp{Y}=Z$, the second argument is taken to be =, because of how TeX decides what the argument to a command is. Indeed, with \newcommand{\comp}[2]{...} the required arguments are two. In my opinion, the optional argument should be ...

2

An answer without ifthen package: \documentclass[10pt,a4paper]{article} \newcommand{\comp}[2][]{% \def\FirstArg{#1} \ifx\FirstArg\empty \ensuremath{{#2}^{c}}% if #1 is empty \else \ensuremath{#2 \backslash #1}% if #2 is not empty \fi } \begin{document} $X\backslash Y$=\comp[Y]{X} ${Y}^{C}$=\comp{Y} \end{document} An answer with ifthen: \...

4

I'd go with a style, as suggested in the other answer. The problem seems to lie in expandability, as the following working code shows. \documentclass[12pt,a4paper]{article} \usepackage{forest,xparse} \NewExpandableDocumentCommand{\probaweight}{sm}{% \IfBooleanTF{#1}% {}% {node[midway, fill=white]{#2}}% } \begin{document} \begin{forest} [ [...

8

I cannot answer the question about the usage starred macros in forest keys, but it is generally not recommended to use macros that expand to pgf keys. Rather, this is what styles are for. And with styles there is no problem, and the code becomes even shorter. \documentclass[12pt,a4paper]{article} \usepackage{forest} \forestset{el/.style={edge label={node[...

3

You can just define a new command using \newcommand\macroname[<arg count>]{<replacement>} (arguments are used by #<num>, up to 9 arguments are supported), to get an a bit more powerful interface you can load the xparse package and use \NewDocumentCommand. The following defines a macro that takes a mandatory argument, followed by an optional ...

5

@egreg explained you why your approach fails: your macro is not expandable. There are two options: either you switch gears and use the expl3 machinery. There is nothing wrong with that. On the other hand, if you use pgf, tikz and/or pgfplots anyway, it is arguably preferable to build these functions into the pgf ecosystem. For many functions, this has been ...

6

The usual problem: \eval is not expandable. Here's a more straightforward implementation with expl3. \documentclass{article} \usepackage{xparse,xfp} \ExplSyntaxOn \NewExpandableDocumentCommand{\CountDigits}{m} { \cp_count_digits:e { #1 } } \cs_new:Nn \cp_count_digits:n { \tl_count:n { #1 } } \cs_generate_variant:Nn \cp_count_digits:n { e } \...

4

They're not equivalent. The space around \mid is \thickmuskip, which is normally twice as big as \thinmuskip (which is what's inserted by \,). If you want a bigger bar as a relation symbol, use \Bigm| (the m stands for “middle” and, by convention, this yields a relation symbol). If you're on LaTeX, don't use . You should also use \Bigl for left ...

1


14

This is just the kind of problem for which the tokcycle package was made. I've only implemented a handfull of the Greek, but you just need a \tcmapto z\zeta type statement for each new mapping. In the MWE, I also use |...| to escape characters back to the original Latin. Macros are automatically intercepted and preserved with the Latin interpretation of ...

1

Something like that: \documentclass{article} \usepackage{scontents} \pagestyle{empty} \setlength{\parindent}{0pt} \begin{document} \section{Definitions} Some text here... \begin{scontents}[print-env=true,store-env=definitions] First definition stored in memory. \end{scontents} More text here... \begin{scontents}[print-env=true,store-env=definitions] ...

0

See if the following MWE is what you looking for: \documentclass{article} \usepackage{tikz} \usetikzlibrary{fit} \newcommand\makenode[2]{\node[draw=red, % to show node border, should be removed inner sep=0pt, fit=(#1) (#2)]} \begin{document} \begin{tikzpicture}%[overlay, remember picture] \...

5

At the start of a paragraph TeX is in vertical mode, so you can use the \ifvmode primitive. Be careful about trailing spaces. \documentclass{article} \newcommand*{\foo}[1]{% \ifvmode Hello #1% \else (hello #1)% \fi } \begin{document} \foo{baz} says the quick brown fox jumping over the lazy dog. The lazy dog says bark \foo{baz} to the ...

5


1

I assume that your “strings” are sequences of printable character tokens. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewExpandableDocumentCommand{\pad}{D(){10}O{~}m} { #3\prg_replicate:nn { #1 - \tl_count_tokens:n { #3 } } { #2 } } \ExplSyntaxOff \begin{document} \typeout{Pad to 10 with spaces} \typeout{|\pad{a}|} \typeout{|\pad{...

0

Usually curly opening braces { and curly closing braces } have a special meaning in (La)TeX: The opening curly brace usually has category code 1(beginning of group). The closing curly brace usually has category code 2(ending of group). Under normal circumstances explicit beginning-of-group-character-tokens and explicit ending-of-group-...

1

\documentclass{article} \makeatletter \newcommand\padtoten[1]{\zzzz{}#1 \\ } \def\zzzz#1#2 {% \ifx\\#2% \expandafter\@secondoftwo \else \expandafter\@firstoftwo \fi {\zzzz{#1#2\space}}{\zz#1\space\space\space\space\space\space\space\space\space\space\zzz}% } \def\zz#1#2#3#4#5#6#7#8#9{#1#2#3#4#5#6#7#8#9\zzz} \def\zzz#1#2\zzz{#1} \begin{document} \typeout{|\...

1


2


1


5

This might be a partial answer. You can define a color series and vary, say, the hue value. The perhaps more important information is that \extractcolorspecs allows you to extract the color specifications of a given color. This can be converted to a given color scheme with \convertcolorspec. The last two commands have been merged to the \convertdirectly ...

Top 50 recent answers are included