Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [macros]

{macros} is for questions specifically concerning TeX's macro processor. Note that, because TeX uses macros ubiquitously, most questions about code that uses macros are not looking for information about how macros work, and so are not appropriate for this tag.

0
votes
1answer
24 views

Illegal parameter number in definition

I found a nice solution to edit the look of hyperlinks, but I have another problem: \documentclass{article} \usepackage{hyperref} \newcommand{\link}[1]{\href{#1}{#1}} \begin{document} % error: ...
0
votes
1answer
43 views

Is there a way to define \xmat*{M}{n}{m} in the physics package

As titled, I want the command\mqty(\xmat*{M}{n}{m}) to generate a matrix like this: $$ \begin{pmatrix} M_{ 11 } & M_{ 12 } & M_{ 13 } & \cdots & M_{ 1m } \\ M_{...
3
votes
0answers
76 views

Avoid passing an empty [optional argument] an environment (with verbatim content) using xparse?

this query is related to How to pass an optional argument to an environment with verbatim content? (whose solution did not work in my case) and with Emulating @ifnextchar in expl3 (which is the one I'...
0
votes
0answers
48 views

Typesetting journal names and abbreviations

I am confused. What is the proper / accepted way of using the journal macros in bibliography? I have found about 3 different sources, and each of them has an incomplete set of the journal macros that ...
0
votes
1answer
28 views

How to activate or deactivate babel layout locally

Consider this example, how to deactivate tabular layout in RTL context \documentclass{article} \usepackage[nil,bidi=basic-r,layout=counters.lists.tabular]{babel} \babelprovide[import, main]{arabic}...
0
votes
2answers
21 views

Listing in a command error: Text dropped after begin of listing on input line

While I wanted to test some alignment options to ask another question regarding to listings, I have encountered a problem that I was not expecting. Consider the following code: % Preamble \...
4
votes
2answers
233 views

Keep at all times, the minus sign above aligned with minus sign below

How can I change the frg command such that I can create and maintain at all times the minus sign above aligned with minus sign below? PS: If you can show how to include a font setting for the whole ...
0
votes
1answer
29 views

Define variables in document so that macro definition goes into preamble

I've written some macros to add OMR characters to the generated document. The OMR characters are needed for an envelope inserter machine. When I want to print OMR characters for a double-sided ...
5
votes
2answers
56 views

How to extend the elements package to print melting and boiling points?

To my propose I would like to extend the elements package to print too the melting and boiling points of chemical elements. Using the same logic used in elements package, I thought about creating ...
0
votes
0answers
25 views

Mathjax: use the parameter in the \style [closed]

Please tell us this is acceptable? I wrote the following sample: <script type="text/x-mathjax-config"> MathJax.Hub.Config({ showProcessingMessages: true, jax: ["input/TeX"], tex2jax: {...
0
votes
1answer
32 views

Remove the output of a custom command \fundinginfo{} in a custom class

For academic purpose, I am using the whiley-article document class that I found in [overleaf]. My problem is that I want to remove the "funding information" output, which is generated by the \...
10
votes
2answers
242 views

How can I reduce the gap between left and right of \cdot with a macro?

MWE \documentclass[a4paper,11pt,border=1pt]{standalone} %\LetLtxMacro{\oldcdot}{\cdot} %\renewcommand{\cdot}{\!\cdot\!} <-- Like this \begin{document} $3\cdot 10^8$ m/s \end{document} I'm getting ...
0
votes
0answers
78 views

Replacing all custom macros and standardizing papers written in TeX [duplicate]

I would like to be able to replace every single user-defined macro in papers written in TeX by its definition. That is, if TeXing is considered to be a function f and my standardizing script is ...
0
votes
0answers
9 views

Pass second argument as the default first argument in a newcommand [duplicate]

I'm trying to do something along these lines: \newcommand{\pcite}[2][#2]{( #1 \cite{#2} )} I.e. make it so that, if an explicit argument is used, then use it, otherwise re-use the second argument as ...
1
vote
1answer
27 views

Local variable to a package

I am defining my own latex package mypackage.sty. How to define a local command such that: mycommand If mycommand is already defined elsewhere it will be locally redefined just inside the package If ...
5
votes
2answers
179 views

Use second argument for optional first argument if not provided in macro

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 ...
4
votes
2answers
99 views

Different macro behavior when used in another macro

Please consider the following MWE : \documentclass{article} \newcommand{\mymargin}{\hspace*{3em}} \newcommand{\innerbox}[1]{\mymargin\fbox{#1}\mymargin} \newcommand{\outerbox}[1]{\fbox{#1}} \begin{...
1
vote
2answers
53 views

LuaLaTeX: Extract basename from path

My question is closely related to LuaTeX: Split path string for use in macros. However, in contrast to this, I would like to have the basename. For example, I am interested in file from /path/to/file....
1
vote
1answer
49 views

Modeling a mapping from strings to lists of strings in LaTeX3

I'd like to work on a data structure using expl3. This data structure would be read from and written to the .aux file in the following format (this is my proposal—I'm open to better suggestions, of ...
1
vote
1answer
28 views

How to automatically label using theorem counter?

Someone please help me! I have some custom environments and I want to label them according to theorem counter. Means, that I get a numbering like Def. 1.1, Thm. 1.2 and so on. Right now, I have to ...
3
votes
2answers
211 views

Command for nulifying spaces (String.trim()) in latex

I want to declare a variable in class that takes in the font name from the preamble of the TeX file. Something like \docFont{<Variable>}. Is there a command that could nullify the space key in ...
4
votes
2answers
48 views

How to resolve clashing definitions of \comment in comment.sty and changes.sty without affecting either's interface?

I'm writing a package that uses both changes (v3.1.2) and comment (v3.8), and I'd like to expose their functionality to consumers of my package without having to modify either one's interface. The ...
2
votes
1answer
24 views

Problem with stored values, macro options, and interaction with other package

Apologies for the rather general title, while trying to sort out a very specific problem: I'm trying to enhance the framework that Alan Munn provided here to represent naturally occurring discourse (...
0
votes
1answer
65 views

How to define a TikZ arrow macro with custom label as an argument

I want to define a custom arrow shape as a \newcommand macro that takes one argument, the label that should appear to the right of the arrow. However the following code doesn't work in the preamble: \...
1
vote
1answer
41 views

Reset stored values at pagebreaks and environment boundaries

Based on this question, I have created a simple macro that prints and stores its argument, and if it is issued again with the identical argument it prints nothing: % !TEX TS-program = xelatexmk \...
7
votes
2answers
370 views

How to write a macro that is braces sensitive?

In the xparse package, there is the g type of argument which captures things inside a pair of TeX group tokens. This makes it possible to define commands \foo that behaves differently for \foo{a} and \...
4
votes
1answer
86 views

Test if tikzmark exists on same page

Apologies for flooding the site with tikzmark problems ... :) I know that with \iftikzmark I can test if a given tikzmark exists in general. Is there a way to test if a particular tikzmark exists on ...
1
vote
1answer
117 views

How to expand a \macro (or a copy) to save in a list at end of environment in xparse (expl3)?

I am trying to encapsulate a couple of environments to pass them to lists using xparse/expl3. I have defined a one command and two environments and I have had a problem with one of them. I use the ...
3
votes
1answer
108 views

LaTeX: Why are digits allowed in environments, but forbidden in commands?

Finding out that I can have an environment named env2, but no command cmd2, I read Why are some characters not allowed in command sequences, but still I wonder: Why are digits allowed in environments,...
1
vote
1answer
23 views

Inclosing \section in \vbox failed with: “Something's wrong--perhaps a missing \item. }”

I wanna put some complex commands (e.g. \section and \chapter) inside a box (\vbox) so later I can compute the height of the block contains the text. Here is the full example: \documentclass[11pt]{...
0
votes
0answers
24 views

Remapping the up/down arrow keys in TexStudio so that I can move up and down within the auto-completion suggestion box

I created shortcuts in TexStudio for the arrow keys (Ctrl+J, Ctrl+L, Ctrl+I, Ctrl+K for Left, Right, Up, Down) so that I can keep my fingers on the homerow keys, rather than moving them to the bottom-...
0
votes
0answers
25 views

How do I remove all occurrences of certain latex commands from a tex file

In my tex file I have a bunch of commands of the form \bla{ ... }, where the ... may span several lines. These commands \bla{ ... } contain some notes for myself, and should be removed from the tex ...
2
votes
1answer
90 views

Get value of a counter

Consider this code: \documentclass{report} \newcounter{counterA} \newcounter{counterB} \begin{document} ... \setcounter{counterA}{2} \setcounter{counterB}{3} \addtocounter{counterB}{counterA} \end{...
6
votes
3answers
313 views

Expand `ifthenelse` immediately

Consider this script: \documentclass{report} \usepackage{ifthen} \newcommand{\thesissize}{SHORT} \begin{document} \setcounter{page}{ %3 \ifthenelse{ \equal{\thesissize}{SHORT} }{3}{...
1
vote
1answer
23 views

How to re-order \addcontentsline?

This question may sound similar to what has been asked before, but I tried to do a minimalistic implementation (stealing some code from the verbatim package). Also I don't really know TeX, just basic ...
0
votes
0answers
47 views

Commands vs keys/values for setting up a document: what an own document class should provide?

This question somehow extends the question "Package option vs setup command". I'm currently writing a class dedicated to students reports for both academic projects and internships. This class ...
4
votes
2answers
37 views

converting several comma-separated lists into a table, one column per list

I have been searching on here for information about comma separated lists, but the only info I have found is how to sort, or iterate over a single list, which isn't quite what I need. If there is a ...
19
votes
2answers
734 views

Is it canonical bit space?

I have this simple code, \documentclass[12pt]{book} \usepackage{mathtools} \usepackage{newtxtext} \usepackage[lite]{mtpro2} \begin{document} $d\bar{p}$ and $dt$. \end{document} with this output, I ...
1
vote
0answers
37 views

LaTeX command returning its argument unalteredly

I would like to define a new command, called \datum{}, which returns its argument without any modification: e.g., \datum{5} gives 5 without any change in format. Could you please help me how to ...
7
votes
1answer
50 views

Use of \noexpand in the implementation of \TextOrMath for eTeX

In latexrelease 2015/01/01, there are two implementations of \TextOrMath: one for regular TeX, the other one for eTeX-like engines (more precisely: those which support \protected). My question ...
7
votes
2answers
149 views

Create test of text direction (luatex)

With luatex there is \textdir to change text direction and tex.textdir which give string representing text direction. I have created this macro to test text direction which supposedly gives TLT ...
2
votes
2answers
49 views

Is it possible to make macros immediately followed by CJK chararacters work?

For example, it reports error when I write (? stands for any CJK character) \TeX?????? Since \TeX?????? is not a defined command. To make it right I have to insert a space or {} after \TeX. But ...
4
votes
4answers
50 views

Macro to create controlled lines over numbers

I want to create a macro in order to create the following effect: Let's suppose this command is called command. Then I want the commands below to provide the image I've put after. \command{} \...
0
votes
0answers
26 views

Do TeXStudio Macros allow for conditionals?

I am trying to get a conditional to work within a TeXStudio script macro. Specifically, this is what I have: %SCRIPT txt = cursor.selectedText() editor.write("\\left\\langle "+txt+" \\right\\rangle") ...
2
votes
1answer
75 views

Create custom note boxes

I am trying to create custom info boxes (very similar as in awesomebox package). The and everything sims is fine except when the box is not surrounded with some text. Then I get an error There's no ...
3
votes
3answers
229 views

How can I separate the number from the unit in argument?

Let us say that I have a function, in which I give a number plus a unit. I would like to get only the number, is it possible ? Here is a MWE: \documentclass{article} \usepackage[utf8]{inputenc} \...
0
votes
0answers
17 views

Measure the remainder of a page if it has a title and inserting that into a dynamic command

Okay, so I'm currently writing a report (in the article class) which has a section full of chemical spectra. I figured that two spectra per page is a good number, so I write \RequirePackage{calc} \...
1
vote
1answer
47 views

How to override command on my preamble, after its redefinition by my class with renewcommand?

I use this document class abntex2 from: https://ctan.org/pkg/abntex2?lang=en, but when I generate this: \documentclass[12pt]{abntex2} \renewcommand{\listfigurename}{Lista de Figuras} \begin{...
2
votes
2answers
66 views

Redefining symbol midway through a document

I am trying to have one command (\phi) draw two different symbols (\varphi and regular \phi) in the same document. I have tried this with the below: \documentclass{article} \usepackage{amsmath, ...
2
votes
1answer
93 views

Define command that accepts \\ in arguments

I am trying to define a new command \dfix that can handle newlines in its arguments. The command works as expected when the arguments have no \\ in them, but LaTeX produces errors if I do include ...