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

New answers tagged

2

You can look in the source, the english default definitions are \def\reftextfaraway#1{on page~\pageref{#1}}% \def\reftextpagerange#1#2{on pages~\pageref{#1}--\pageref{#2}}% So you could use similar definitions or using normal latex redefinition syntax: \renewcommand\reftextfaraway[1]{on page foo~\pageref{#1}}% \renewcommand\reftextpagerange[2]{on pages~\...


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

You can use expl3's property lists to store the data for you, and then loop through the items in the property list to lay the table out. I defined a command \DeclareImpact{<label>}{<impact>}{<countermeasure>}, which replaces your \newcommand{\Impact<label>}{<impact>} and \newcommand{\Countermeasure<label>}{<...


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

Here you go: %SCRIPT var d = new Date(); var nn = "_"+ d.getFullYear()+"_"+ d.getMonth()+"_"+ d.getUTCDay()+".tex"; var fn = editor.fileName().replace(/.tex$/, nn); app.fileSaveAs(fn); This will open the save as dialog when you close a file. You can change the trigger however you want. http://texstudio.sourceforge.net/manual/current/usermanual_en.html#...


2

declare \hgnum to be a robust command, change \def\hgnum#1{{\hg\expandafter\hgnumx\the\numexpr10000000+#1\relax}} to \DeclareRobustCommand\hgnum[1]{{\hg\expandafter\hgnumx\the\numexpr10000000+#1\relax}} Unrelated but you should delete the erroneous \\ which are generating bad output and the warnings: Underfull \hbox (badness 10000) in paragraph at lines ...


2

As noted in comments \def\aa{\value\modulo{152123}{10}} the command name should not be \aa as that over-writes a standard latex command. \value is a macro that takes a single argument so here, with no braces it gets the argument \modulo (not \modulo{152123}{10}). The intended usage is \hgunits{\aa} but \hgunits is a simple \ifcase checking values 0-9 ...


3

Following the usual notations for projective space, I use: \documentclass{amsart} \usepackage{xparse} \NewDocumentCommand\Proj{e^e_d()}{% \IfNoValueTF{#1}{\IfNoValueTF{#2}{\mathbb{P}}{\mathbb{P}_{\!#2}}}% {\IfNoValueTF{#2}{\mathbb{P}^{#1}}{\mathbb{P}^{#1}_{\!#2}}}% \IfValueTF{#3}{\!\left(#3\right)}{}% }% \begin{document} \(\Proj^n, \Proj_k, \...


8

In LaTeX you can define a new macro with \newcommand. \newcommand can have an optional star, which determines whether arguments of the newly created macro can contain a \par (or two consecutive newlines) or not. The next is the name of the new macro. After that are two optional arguments, the first specifying the number of arguments and the second if used ...


1

\documentclass{article} \usepackage{fontspec} \usepackage{enumitem} %I don't have this font and you want teh updated verison with Unicode ordering. %\newfontfamily\ngg{NewGardiner} \newfontfamily\ngg{Segoe UI Historic} %you do not need a counter and want to start from 77824 not 13000 %\newcounter{nw} %\setcounter{nw}{13000} %\renewcommand{\theenumi}{\...


3

One option is to put the content in a fitted box using the fitting library and the tcolorbox package (see chapter 21 of the tcolorbox manual). Several fitting algorithms are available to fit text to the nominated height and width of a box. \documentclass[20pt]{beamer} \usetheme{Warsaw} \usepackage[fitting]{tcolorbox} \newcommand*{\mytext}{This is a random ...


2

By using environ package and pgffor (just to simplify the \loop): \documentclass[12pt]{beamer} \usetheme{Warsaw} \usepackage{environ} \usepackage{pgffor} \newcounter{boxCounter} \newsavebox{\boxA} \newsavebox{\boxB} \newsavebox{\boxC} \newsavebox{\boxD} \newlength{\availafter} \NewEnviron{autotext}[1][0.5cm] {\setcounter{boxCounter}{0}\foreach \mysize in ...


7

Rather than using LaTeX to manually define a mapping between typed letters and Greek characters, you may find it more convenient to simply type the Greek characters as-is into your document. For this you will need to use XeLaTeX or LuaLaTeX, the unicode-math package, an OpenType math font, and a keyboard layout that permits direct entry of Greek letters. ...


27

Fill in the table: \documentclass{article} \newcommand{\greek}[1]{\begingroup\setuplatintogreek#1\endgroup} \newcommand{\setuplatintogreek}{% \mathcode`a=\alpha \mathcode`b=\beta \mathcode`g=\gamma \mathcode`d=\delta \mathcode`e=\varepsilon %... } \begin{document} $abgde+\greek{abgde}$ \end{document}


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

The solution to the problem is to load the letltxmacro package and do: \LetLtxMacro\iso\cong \LetLtxMacro\cong\equiv A little explanation: your reasoning that "TeX read commands from top to bottom" is correct. After you do \newcommand{\iso}{\cong}, the command \iso will make a ≅ as you expect, but not how you expect it to. After the \newcommand above (...


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

As long as you don't mind the spaces being implicit, here is a way. \documentclass{article} \usepackage[T1]{fontenc} \newcounter{tencount} \makeatletter {\catcode`\ =12 \gdef\xsp{ }} \newcommand\maketen{\begingroup\catcode`\ =12 \maketenauxa} \newcommand\maketenauxa[1]{% \setcounter{tencount}{0}\def\tmp{}\maketenauxb#1\@sptoken\@sptoken \@sptoken\@...


2

\def\foo#1{...#1...} is the primitive TeX way for defining one-argument macros. In a LaTeX context, the code should have \newcommand*{\Assign}[1]{...} \newcommand*{\Assigned}[1]{...} so as to check whether the macros are already defined and not be surprised of bizarre results. The purpose of the code is to make an array of comma separated lists of ...


1

A syntax for a custom macro can be \newcommand{\<macroname>}[<number of arguments>]{<macro code with #1 as first argument, #2 second ...>}. In your case, the macro can be defined as \newcommand{\expectation}[1]{\langle \psi #1 \psi \rangle}. More information can be retrieved from wikibooks/latex/macros. You should also have a look at the ...


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