New answers tagged macros
4
votes
No spacing after binary operator after math operator
TeX follows its own rules. With
\int f(x) \diff{x} + y
(note that you cannot define \intop that's already taken) you have
Op Ord Open Ord Close Op Bin Ord
but the combination Op Bin is invalid and ...
- 1.1m
3
votes
How to write a latex macro to reference a particular time in a set of youtube videos?
With the assumption that hours are quite rare in your links, the following makes them an optional argument defaulting to 0. Else this is pretty similar to the other answers, I've opted for a two-step ...
- 53.1k
3
votes
Accepted
How to write a latex macro to reference a particular time in a set of youtube videos?
In your command you are using mandatory arguments to your command. I would advise against it, since sometimes it might be the case that you don't want to specify a particular time. For this, using ...
- 2,621
5
votes
How to write a latex macro to reference a particular time in a set of youtube videos?
Code:
\documentclass[11pt]{article}
\usepackage{hyperref}
\newcommand{\youTubeRef}[5]{\href{\csname#2\endcsname\&t=#3h#4m#5s}{#1}}
\newcommand{\first}{https://www.youtube.com/watch?v=3anNG7TfHSQ}
...
- 4,006
0
votes
Accepted
Condense paragraph into one line in LaTeX
The solution I was after is below.
Idfix -> hard line break -> set at 0 (smart scoping and join lines).
Now all i needed to do was set a short cut key for this.
configure texstudio -> ...
- 213
4
votes
Accepted
How can I create a plain TeX macro that performs differently depending on whether or not it is called from within an \item?
Similar to what cabohah suggested in a comment, but with a small safety check: I redefine \item to use a new length \itemindent instead of \parindent, and set the former to be \parindent plus 1sp. ...
- 27.2k
3
votes
Accepted
Difference between `\newcommand{..}[1]` and `\NewDocumentCommand{..}{m}`
The difference in this context is that \NewDocumentCommand uses e-tex \protected\def so the command does not expand in a \write. You could use \NewExpandableDocumentCommand to define an unprotected ...
- 707k
4
votes
How can I create a plain TeX macro that performs differently depending on whether or not it is called from within an \item?
Following the suggestion of cabohah in the comments:
\newif\ifinitem
\initemfalse
\def\mymacro{\ifinitem hi!\else bye\fi}
\def\item{\par\initemtrue\hang\textindent}
\let\oldpar\par
\def\par{\...
- 34.5k
6
votes
Create a simple Latex macro which expands the format to sequence
This solution is a purely (e-)TeX one. It uses the same idea as Οὖτις's, but it doesn't require that the input be a control sequence (the input must be a character).
I got rid of the optional argument ...
- 471
3
votes
Create a simple Latex macro which expands the format to sequence
What about this?
\documentclass{article}
\usepackage{pgffor}
\newcommand{\macro}[2]{%
\foreach \n in {1,...,#1}{%
#2%
\ifnum\n<#1 + \fi
}%
}
\begin{document}
$\macro{5}{x^\n y^\n}$
$...
- 619
9
votes
Create a simple Latex macro which expands the format to sequence
You can define an auxiliary macro and do the replacement.
\documentclass{article}
\usepackage{amsmath}
\ExplSyntaxOn
\NewDocumentCommand{\makesum}{O{N}m}
{
\akkapelli_makesum:nn { #1 } { #2 }
}
...
- 1.1m
5
votes
Create a simple Latex macro which expands the format to sequence
You did not tell whether with the result of \macro the focus is on obtaining the set of tokens, e.g., for defining another macro from it, or is on obtaining some nice typesetting in the pdf file.
If ...
- 26k
5
votes
Accepted
Create a simple Latex macro which expands the format to sequence
If you are willing to write \N for the symbol to be replaced, I can offer the following solution.
\documentclass{article}
\usepackage{amsmath}
\newcommand{\macro}[2][]{
\def\N{1} #2
+
\...
- 2,250
2
votes
Create a simple Latex macro which expands the format to sequence
You are almost there. A few remarks:
macros are called \newcommand in LaTeX
you can't name them the way you did
instead, use simple terms using characters only (no digits, _ etc.)
the first parameter ...
- 3,455
3
votes
Alternatives to the physics package
There is now the package physics2 which takes a "modular" approach (command sets are loaded via \usephysicsmodule{<module>}). This allows it to support multiple (but sometimes mutually ...
- 1,315
1
vote
Understanding a \@for loop
A solution using the \ekvcsvloop provided by expkv. I also added a small key=value interface with expkv-cs, the supported keys are align and formatter (the latter will get the text of each row as ...
- 53.1k
1
vote
Accepted
How to add rows to a table via a command
You need to tell tabularray to first expand the \@history macro before typesetting the tabular. You can do this using the expand option (see section 3.2.3 "Expand Macros First" of the ...
- 32.3k
3
votes
Why is \textsc not working on this tabularray?
As @DavidCarlisle points out in his answer, the Computer Modern text font family doesn't include the bold/smallcaps combination.
The remedy? Use a font that does provide the needed weight/shape ...
- 469k
5
votes
Why is \textsc not working on this tabularray?
This is unrelated to the table or pythontex.
latex warns
LaTeX Font Warning: Font shape `OT1/cmr/bx/sc' undefined
(Font) using `OT1/cmr/bx/n' instead on input line 32.
That is, there is ...
- 707k
5
votes
LaTeX3: elegant way to forward arguments (tokens, star, embelishments) to another command
Don't. It's not what \NewDocumentCommand is for.
Anyway, first fix the arguments in \mynewcommand: your list is off.
\documentclass[]{article}
\NewDocumentCommand{\mycommand}{st't-t.e_O{}m}{%
I am ...
- 1.1m
3
votes
Accepted
LaTeX3: elegant way to forward arguments (tokens, star, embelishments) to another command
Is this what you want? I think you must have overlooked argument #3 (the argument s-) in \mynewcommand, so I took the liberty of adding it.
\documentclass[]{article}
\NewDocumentCommand{\mycommand}{...
- 11.9k
0
votes
Create my customized version of \fnsymbol
Define your sequence of strings.
\documentclass{article}
\makeatletter
\NewExpandableDocumentCommand{\mynumbering}{m}{%
\ExpandArgs{c}\@mynumbering{c@#1}%
}
\ExplSyntaxOn
\...
- 1.1m
1
vote
Create my customized version of \fnsymbol
For getting ordinal numbers written out there seem to be two packages suited for that:
fmtcount
numspell
They have a slightly different interface in that numspell only works with actual numbers out ...
- 103k
2
votes
Accepted
TexStudio Macro to lower case words
All ECMAScript functions/methods are supported, hence the string method toLowerCase() does the job.
%SCRIPT
cursor.replaceSelectedText("\\gls{" + cursor.selectedText().toLowerCase() + "}...
- 23.6k
1
vote
Accepted
Cross Referencing and floating Point calculation inside of a tabbing environment
The code referenced in the linked A was written by me.
When writing it I overlooked that with the zref-package assignments for introducing new properties (\zref@newprop) are done globally (not ...
- 26k
1
vote
Configuring custom command for name and emails
Here's a quick way. I see no advantage in giving the optional argument after the mandatory one, so I use the standard version. You can surely change that, if you want.
\documentclass{article}
\...
- 27.2k
1
vote
Summarize all costs and show the result in different places of the document
Store the overall value only once at the end of the document. I wouldn't produce links, it doesn't make much sense as there is no location associated with the overall value. Do not allocate a new ...
- 309k
2
votes
Accepted
Changing the style of unnumbered chapter to chapter
You need to create a \@makeschapterhead (version of \@makechapterhead for the star-chapter command, note the "s" between "make" and "chapter").
I have adjusted the width ...
- 4,006
3
votes
Accepted
LaTeX command that defines two new commands, one as a capitalized version of the other
If you prefer TeX primitive commands instead of Expl3 commands (similar to me) then yo can do:
\def\DeclareDoubleMathOperator#1{\ddmoA#1\end}
\def\ddmoA#1#2\end{\uppercase{\ddmoB#1}#1{#2}}
\def\ddmoB#...
- 63.2k
1
vote
Accepted
Automatically customizing the front cover of different memoirs
The problem is that \CoverBackgroundColor does not expand to a color, but to a set of instructions for printing a color name.
Replace the code in mycover.tex into
%%% mycover.tex
\ExplSyntaxOn
\...
- 1.1m
2
votes
Accepted
@for loop variable name printed instead of contents in tabbing environment
Table cells create groups, so any non-global assignment is lost when TeX goes to another cell (here, when you use \> to go to the next column or \\ to the next row). \@for does a local assignment ...
- 69.2k
3
votes
LaTeX command that defines two new commands, one as a capitalized version of the other
There are better methods, nowadays.
\documentclass{article}
\usepackage{amsmath}
\ExplSyntaxOn
\NewDocumentCommand{\DeclareDoubleMathOperator}{m}
{
% lowercase version
\cs_if_exist:cF { #1 }
...
- 1.1m
0
votes
Accepted
Redefine \varprojlim and \varinjlim to get more pleasant arrows
Add a small strut, here the depth is 0.2ex, adjust to suit. The braces around \lim are necessary to avoid TeX inserting spaces.
\documentclass{article}
\usepackage{kpfonts-otf}
\newcommand{\limstrut}{...
- 1.1m
1
vote
Accepted
Summarize all costs and show the result in different places of the document
Probably a mechanism where you can specify via optional argument where to place the anchor for hyperlinks and the cross-referencing-label does what you want.
(You seem to want not the Euro symbol from ...
- 26k
0
votes
Can you not pass argments to commands using keys?
I must have made some typo because I am certain I did this, which works as I have wanted it to. I decided to retry the obvious solution:
\newcommand{\AddSvgHeight}[1][]{%
\ifthenelse{\boolean{...
1
vote
Can the BST file for BIBTEX be composed of several files?
No, the bst syntax does not provide a function to load files other than .bib. You may consider storing the abbreviation definitions (@string) in a .bib file.
- 635
0
votes
Parsed word segment in second function can not be compared to string in latex?
The following is inspired by egreg's answer:
\firstwordscase with its 2nd argument does "text-expansion", strip off leading and trailing space tokens and then extract at most as many space-...
- 26k
13
votes
Accepted
First letter in argument of "\affil" not being output if the first letter is "L"
Well, there is a bug in the document class IEEEmce (which can be found via the this link). I actually do not recommend using this document class, as it seems not to adhere to best practices when it ...
- 32.3k
0
votes
lilypondfile in macro, with filename as argument
As pointed by Ulrich Diez, lyluatex allows such definitions, but with some caveats you should be aware of, that are mentioned in the documentation. See the "Examples" section, "Wrapping ...
- 99
2
votes
Parsed word segment in second function can not be compared to string in latex?
For the sake of variety, here's a LuaLaTeX-based solution. It consists of two LaTeX utility macros, called \FirstPart and \foo, that make \directlua calls to Lua functions called, you guessed it, ...
- 469k
2
votes
Parsed word segment in second function can not be compared to string in latex?
It's not really clear what you want to achieve. Maybe something like this?
\documentclass{article}
\ExplSyntaxOn
\NewExpandableDocumentCommand{\firstwordscase}{mmm}
{
\ise_firstwordscase:enn { \...
- 1.1m
1
vote
Parsed word segment in second function can not be compared to string in latex?
Probably a command \foo which only by expansion-methods tests whether its argument (after expansion and) after appending a space starts with 1.⟨space⟩Book⟨space⟩ is sufficient?
\makeatletter
%%========...
- 26k
2
votes
Accepted
Optional argument in optional argument causing errors
It seems quite a complicated set of commands… Anyway, stick to \NewDocumentCommand.
\documentclass{article}
\usepackage{amsmath}
\NewDocumentCommand{\restr}{mm}{#1\IfBlankF{#2}{|#2}}
\...
- 1.1m
0
votes
Command to create table of images
Perhaps you need something like this?
% !TeX program = lualatex
\documentclass{article}
\usepackage{caption,subcaption}
\usepackage[margin=1in]{geometry}
\usepackage[draft]{graphicx}
\usepackage{...
- 1,428
1
vote
I'm trying to use armtex in latin "mode", but macros do not work properly
You need to call the Armenian parts as argument to the font selection commands listed in section 4 of the manual.
\documentclass{article}
\usepackage[latin]{armtex}
\begin{document}
\section{...
- 1.1m
2
votes
texlive tlmgr update: what's the best configuration
I asked at the homebrew forum and learned that the use of tlmgr is blocked.
As @samcarter_is_at_topanswers.xyz suggests in her/his comment above, we should download the MacTex package from its ...
- 737
0
votes
Accepted
Latex newcommand with key-values uses value of last call for each call
Probably nesting \PassFirstToSecond/\Exchange does the trick:
\makeatletter
\RequirePackage{keyval}
\define@key{test}{unit}{\def\thisunit{#1}}%
\define@key{test}{ref}{\protected@edef\thisref{#1}}%
\...
- 26k
4
votes
ifcase eats up letters
Unrelated to \ifcase you have \newcommand{\GCDorLCM}[2] so define it with two arguments but you only use #1 so #2 (which is o here) is discarded.
\documentclass{article}
\newcommand{\GCDorLCM}[1]{\...
- 707k
3
votes
Accepted
what is definition of "\@nobreaktrue"?
TeX has a build in primitive \show to show the meaning of a command sequence. For example
\show\TeX
\bye
in plainTeX writes:
> \TeX=macro:
->T\kern -.1667em\lower .5ex\hbox {E}\kern -.125emX.
l....
- 3,703
1
vote
ifcase command that changes color does not work
If you don't fully understand how TeX's macros and primitives (such as \expandafter in this case) work, I recommend writing easy-to-understand macros that does not use them (see the modified \...
- 4,971
Top 50 recent answers are included
Related Tags
macros × 7910expansion × 456
tikz-pgf × 450
environments × 410
math-mode × 366
conditionals × 339
tex-core × 312
tables × 281
spacing × 257
optional-arguments × 202
errors × 188
xparse × 184
expl3 × 176
cross-referencing × 136
counters × 130
arguments × 130
sectioning × 129
packages × 122
formatting × 115
programming × 110
strings × 101
etoolbox × 100
beamer × 97
symbols × 96
color × 96