New answers tagged

0

As a comment above states, expl3 syntax applies special meaning to the underscore symbol _, therefore the usage of macro \sb{...} is required.


2

Just make the definition global: \newcommand{\setfoo}[2]{% \expandafter\gdef\csname tomasz@#1\endcsname{#2}% } \newcommand defines a macro in the current group (thus obviously in child groups). When this group is finished, the definition is lost: the macro definition is restored to the state it had before the group was started. In the case of a ...


1

(This is part 2 of my answer which consists of two parts. Here is a link to part 1 of my answer.) By now the tokens that are to be delivered in the different cases were "hardwired" in the macro-definition. But you can combine such delimited-argument-based forking-mechanisms with mechanisms for grabbing the k-th element of a list of undelimited arguments ...


1

(This is part 1 of my answer which consists of two parts. Here is a link to part 2 of my answer.) You can implement such testing by means of delimited arguments also. With tests based only on delimited arguments, no \if-switches are applied, thus such tests cannot be fooled by unbalanced \else or \fi or \endcsname and the like. With tests based only on ...


4

Here's a fairly general macro where you can set the mode as an optional argument: choose between round (default), floor, ceil or nearest. The \generalrepeat macro accepts the starting point (an integer), the step (an integer, default 1) and the end point (a floating point number). The \myrepeat macro is a reduced version, always starting from 1 with step 1....


3

You can use the expandable functionality of xfp: \documentclass{article} \usepackage{pgffor,xfp} \newcommand{\myrepeat}[2]{\foreach \n in {1,...,\fpeval{floor(#1)}}{#2}} \begin{document} \myrepeat{6}{x} % prints xxxxxx \myrepeat{3.2}{x} % prints xxx \myrepeat{8.1 * sin(pi / 6)}{x}% prints xxxx sin(pi/6) = 1/2; 8.1 * 1/2 = 4....


6

One approach would be this. ceil and floor are alternatives to round. There are also command versions of each, as Alan Munn mentions in a comment, i.e. \pgfmathround{#1}, \pgfmathceil{#1}, \pgfmathfloor{#1}. \documentclass{article} \usepackage{pgffor} \newcommand{\myrepeat}[2]{% \pgfmathparse{round(#1)}% set rounding function here \foreach \n in {1,......


4

\ifx compares two tokens without expansion, so if you pass [ ] to \bpdef, the \ifx test will compare [ with a space and fail. You need to define a temporary macro and compare it with \bptoks. Alternatively you can use \pdfstrcmp (or the equivalent in other engines (\pdf@strcmp if you load pdftexcmds)) to make a string comparison: \documentclass{article} \...


2

The issue is with superscripts, as they are patched by tex4ht at \begin{document}. Your sample compiles correctly when you move definition of the \test macro before \begin{document}. Another possibility is to use the no^ and no_ command line options, but this may broke other things. % https://tex.stackexchange.com/q/499677/2891 \documentclass{amsart} \...


3

With the help of a \protected macro it is possible to come close to what you want. The basic idea is to start with a \protected macro followed by another non-\protected macro. In an \edef (or \write or \expanded or...) the \protected macro will be skipped by TeX and the other macro will expand leaving itself (preceded by \noexpand) and \unexpanded{<stuff&...


2

You can simply use the second definition, as \columnwidth is the same as \textwidth in one-column mode. Actually, I would probably use \linewidth. This way, in case you use your environment inside a list item (itemize, etc.), the minipage will be centered within that item (and the rule length adapted to its width). This is a matter of taste, of course (what ...


5

Here is a pure expl3 reimplementation. The most notable changes are: \Scontents now has argument types O{} +v. By using xparse's verbatim argument type v, the use of the star isn't necessary anymore, as this type automatically detects if a braced argument or a delimiter character follows. The \UDcollectverbarg was removed, because it seems to do what the v ...


1

Here is a solution, using two arguments: the index and the random variables, separated by a |. If you want no index, use an empty argument. If tere is no conditional part,, i.e. if you type no |, no vertical rule will be printed. If you need to use one in your formula which shouldn't be interpreted as a separator, use {|} : \documentclass{article} \...


3

You have several spaces inserted by newlines... \newcommand{\vs}[2]{% \relax\ifmmode \ifemptyarg{#2}% {#1\text{-vector space}}% {#1\text{-vector space }#2}% \else \ifemptyarg{#2}% {$#1$-vector space}% {$#1$-vector space $#2$}% \fi} works. Notice that the "%" after the \ifemptyarg{#2} is not ...


2

\renewcommand respects grouping: \documentclass{article} \newcommand{\foo}[1]{The Status: #1} % define \foo \begin{document} Some text, \foo{Complete} More text, {\renewcommand{\foo}[1]{Status: #1}\foo{Complete}} Some text, \foo{Complete} \end{document} A better solution might be to define a *-variant, which gives even more flexibility, control and ...


0

How about: \documentclass{article} \newcommand{\foo}[1]{The Status: #1} % define \foo \begin{document} Some text, \foo{Complete} \let\oldfoo\foo % save \foo as \oldfoo \renewcommand{\foo}[1]{Status: #1} % renew \foo More text, \foo{Complete} \let\foo\oldfoo % revert \foo to its original definition and so on \end{document}


4

You were on the right track trying to renew \@venn@shade but to do that you need to wrap the \renewcommand in \makeatletter \makeatother. See What do \makeatletter and \makeatother do? You can also modify aspects of the tikzpicture environment used to draw the venn diagram by using the option tikzoptions=. In this way you can modify the colour of the lines ...


1

I suppose that you want to change for the reledmac footnote of the A series (\footnoteA), despite the fact that in your example, you use also standard LaTeX footnote (\footnote) You must redefine \bodyfootmarkA to get the footnote mark smaller in the body. Just take the standard definition, and add a font size command. footfootmarkA to add space after ...


6

As egreg wrote, \csname ... \endcsname defines the control sequence token to be \let-equivalent to \relax if it isn't already defined (you can think of it as a side effect of \csname). With e-TeX extensions, you can use \ifcsname to test whether a control sequence is defined, without defining it (no side effect): \documentclass{article} \newcommand*{\...


0

I'm not sure about your way, or the distance between the text and the mark, but here's a way I got a smaller footnote mark which at least, hopefully, answers part of your question: \documentclass{article} \makeatletter \renewcommand{\@makefnmark}{\hbox{\textsuperscript{\tiny{\@thefnmark}}}} \makeatother \begin{document} Text with a smaller footnote mark\...


2

TeX is a macro expansion language. Definitions are not like functions in a compiled language where the implementation details are hidden and underlying commands can be changed without affecting the defined commands. The definitions are simply expanded in place with each macro being replaced by its replacement text until a primitive is encountered. That ...


2

I think I've got this figured out. Yes, it is possible to render commands defined in the preamble, even when they are defined in loaded from another file. I am using LyX Version 2.3.2 and Ubuntu 16.04 LTS. They key is instant preview. Turn on instant preview Tools >> Preferences Look and Feel >> Display If the option is not there, try following the ...


1

From the introduction in the manual of the gincltex package: This small package builds on the standard LaTeX package graphicx and allows external LaTeX source files to be included like graphic files: \includegraphics[〈options〉]{〈file〉.tex} A LaTeX file included this way should result in an identical display as a tightly cropped EPS or PDF image ...


1

As Ulrich Diez pointed out, this thread contained a suitable solution for my problem. But this solution prohibits calling other macros with the arguments. I wrapped it in another command so I could add label and caption. like so: \usepackage{xparse} \usepackage{tabularx} % I copied & pasted this part: \ExplSyntaxOn \NewDocumentCommand{\newlongcommand}...


2

I suggest a different approach, with an environment: \documentclass{article} \newenvironment{presentation}[2] {\par\noindent\begin{minipage}[t]{\dimexpr\linewidth-3em} \textbf{#1}\\#2\smallskip \begin{itemize}\setlength{\itemindent}{-0.15in}} {\end{itemize}\end{minipage}\par\addvspace{2\bigskipamount}} \newcommand{\present}[4]{\item #1 -- #2 #3 #4} ...


2

Your attempt \present doesn't even call \checknextarg... In order to simplify the code, I'll assume the number of arguments is of the form 4n + 2, where n is a positive integer. Otherwise, more tests are needed. Note: \dimexpr doesn't need parentheses where you put them. \bigskip\\* doesn't make much sense because \bigskip itself is a legitimate ...


4

You correctly set the inner sep to 0 for the node but forgot to do so for the label, which is also a node. Once you set it to 0 (or 0.5pt for the optics) there, you no longer need the negative yshift. I also added a %, and marked the position with <-. \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \usepackage{xparse} \newcommand{\...


0

The unicode-math package is partly backward-compatible, but the rules are slightly different. The \mathbf command still works, but is meant for words in math mode. The recommended way to get individual math symbols is \symbfup or \symbfit. The amsmath command \bold will therefore still work. IF you load an OpenType math font that has a bold version (as ...


1

Using \futurelet you can crank out the cases of the following token being { or } or a space-token. If the following token is none of these tokens, you can have LaTeX process it as macro-argument. Macro-arguments in turn can be examined in various ways. One way of interpreting your vague specifications is: \documentclass{article} \makeatletter \newcommand\...


3

Look for here! Every endline in the body of the definition contributes a space. There is none after \noexpandarg. \newcommand{\glossstep}[2]{% <--- here \expandafter\StrSubstitute\expandafter{\x}{#1}{#2}[\x]} \newcommand{\totalgloss}[5][T P A Q]{% <--- here \noexpandarg \StrSubstitute{#1}{T}{\textit{#2}}[\x]% <--- here \glossstep{P}{/\textipa{#3}/}...


5

The code became a tad long. Much longer than I initially thought it would be. Your conditions aren't too clear, I think. What I implemented (in crappy pseudocode) is: procedure cur_char // (a, b, c, or d) if next_char is lowercase_vowel print replacement (cur_char) // replaces ABCD by PQRS else if next_char is uppercase_X ...


1

RefTeX provides a variable for this purpose called reftex-label-regexps. You have to customize this variable with the appropriate regular expression which can look like this: <%[[:space:]]*fig("\(?1:[a-z-]+\)" Enter M-x customize-variable RET reftex-label-regexps RET, hit the INS button, add the regexp above and hit Apply and Save. In Emacs, it should ...


2

After looking at your MWE for testing I assume that you are happy with LaTeX. The doubling and halving of the amount of consecutive hashes might be a source for problems: When during expansion of a macro delivering the ⟨balanced text⟩ of a definition, (La)TeX will collapse two consecutive hashes into one, i.e., the amount of consecutive hases ...


1

In this code I maintain a (local) token list holding the incrementally updated replacement text; after each \addtohook command, also the inner version of \hook is updated. You can also change the two-parameter macro on the fly with the optional argument. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\addtohook}{O{\...


3

Here's a shameless copy minimal implementation of etoolbox's \apptocmd. I left out all sanity checking of the input macro to keep the code to a reasonable amount. This assumes that: the macro (that is, the hook being added to) is defined, is a macro, has parameters (otherwise the patching can be simply done with \edef and \unexpanded), can be used in \...


0

You can use the prop lists of expl3 to store the relevant data for each entry, and then store the key to each entry in a seq list. Defining a command, say, \apdescribetext which takes the text as argument, you can loop through the seq list and print the text. \apdefine takes three arguments, the airport code, name, and address. \apdescribe takes an airport ...


3

A call to \apdefine defines the three argument variables, as well as the description variable. Then, it appends the airport code to a comma separated list named \airportlist. After each airport is defined via \apdefine, one should invoke the \readlist, which will create a listofitems array named \airports, which can conveniently be used in a \foreachitem ...


2

The question is a little hard to answer as, despite the question title, the example given has no optional argument. (Note the [] following the command is typeset as text not taken as argument delimiter). However it does use the \@ifnextchar construct which would make it fragile, however you can hide that by declaring it as a robust command: \documentclass[...


2

You also get on the terminal and in the .log-file some error-messages of the pattern: pdfTeX warning (ext4): destination with the same identifier (name{cp.1}) has been already used, duplicate ignored The reason is within the ending-part of your computaion-environment the line \setcounter{cp}{0} : When \rcp is carried out, \refstepcounter{cp} is ...


3

Since it seems you are keen to follow the expl3 guidelines, I suggest you take a look at “The expl3 package and LaTeX3 programming” (texdoc expl3) and “The LaTeX3 kernel: style guide for code authors” (texdoc l3styleguide). These are two short documents introducing the basic concepts of expl3 and a preferable coding style. That said, I translated the code ...


4

As pointed out by egreg, what we gain from such a \dynamictable command accepting an “arbitrary number of arguments”, as compared to using standard tabular markup where rows are terminated by \\, is not very clear. But let's study it as an exercise. :-) What happens with your code The error you get is due to the fact that your \checknextline call is ...


3

The following grabs arguments until the next token is not an opening brace. Additionally it takes a variable number of columns and sets them all centred. You can use an optional argument to explicitly specify the table preamble. This one uses tabular but I think you can easily change it to another table environment: \documentclass[]{article} \usepackage{...


2

You need \dimexpr to have the minipage evaluate the expression, and then \dimexpr\textwidth-2\parindent. The rule was not centered because you had \centering active and \hfil\rule{}{}\hfil, but TeX discards glue (which includes \hfil) at the end of a line, so the last \hfil was removed. And with \centering you have \leftskip and \rightskip doing \hfil, so ...


3

Map the input item by item, adding \@. (this is because the last period might follow a lowercase character). \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewExpandableDocumentCommand{\dacr}{m} { \confusedandbemused_dacr:n { #1 } } \cs_new:Nn \confusedandbemused_dacr:n { \tl_map_function:nN { #1 } \__confusedandbemused_dacr_add:n } \...


6

What I do here is set up an recursion. The called \acr macro passes the argument to the helper macro \acraux terminated by two \relax tokens. The helper macro breaks the argument into the "next" token and everything else that remains (terminated by a \relax). It will typeset the "next" token with a trailing dot, as long as that next token is not a \relax....


4

This is easy to do using LaTeX3 regular expressions. In more detail, the code: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand\acr{m}{ \tl_set:Nn \l_tmpa_tl {#1} \regex_replace_all:nnN {([A-Z])} {\1.} \l_tmpa_tl \tl_use:N \l_tmpa_tl } \ExplSyntaxOff \begin{document} \acr{WHO} \end{document} produces:


11

The information on that page is wrong (or at least outdated, all commands in latex2.09 that had an optional argument were fragile, but latex2e has been available since 1993...) the example in the question does not define an optional argument but if you change it so that it does, using the facility of \newcommand to define such an argument you will see that ...


29

The command you defined does not take an optional argument, it takes a delimited argument. If you do: \def\b[#1]#2{.#2.\bf #1} \b[one]two it will work fine, however if you remove the [one] TeX will throw an error: \def\b[#1]#2{.#2.\bf #1} \b two ! Use of \b doesn't match its definition. l.5 \b t wo ? because when you define a command with \def\b[...


2

A control sequence is either defined or undefined. There's no way to say Hey, TeX, if you find a control sequence starting with \cal followed by an uppercase letter, say X, and which is currently undefined, define it so that it does \mathcal{X}. Well, there might be some very fragile ways to do it. The trade between using complex and fragile code or ...


3

\documentclass{article} \usepackage{listofitems,xspace} \newcommand\makecalx[1]{% \expandafter\def\csname cal#1\endcsname{\ensuremath{\mathcal{#1}}\xspace}% } \readlist\callets{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z} \foreachitem\z\in\callets[]{\expandafter\makecalx\expandafter{\z}} \begin{document} Here is \calG and \calZ. \end{document}


Top 50 recent answers are included