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.

171 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
0
votes
0answers
10 views

TexStudio autocompletion stopped working for macros

So I recently created macros (.sty files), which are remotely loaded at in my preamble. There are various points in these macros where I've defined a new command; for example: \def\remark#1#{\...
0
votes
0answers
52 views

How to test for existence of a string in a tex file?

How can I obtain a command that tests for existence of a string in a tex file? Example: if ('foo' is in file.tex) then raise error (You used foo, please don't use foo)
0
votes
0answers
32 views

Redefining `\global\long\def` to always use `\robustify`

I use LyX and the math macros are compiled to LaTeX using \global\long\def\mymacro#1#2{body} (for a binary macro). This leads to me having to \robustify many of those macros. I tried redefining \def ...
0
votes
1answer
35 views

newcommand counter expansion problem

I am trying to write a macro to support producing a sequence of storyboards for an appendix in a two column IEEE paper. Can the value of a counter be expanded immediately for a macro? Currently the ...
0
votes
0answers
37 views

Redefine command to handle empty linebreaks

I have the request to use underline text. I am aware this could be done with \ul (from soul package) which works in most of the scenarios. Somehow this command has a problem to handle properly \href{} ...
0
votes
0answers
35 views

newcommand, renewcommand, providecommand - what about other variants?

See also: What do newcommand, renewcommand, and providecommand do, and how do they differ? We have \newcommand: Acts when command undefined; error otherwise. \renewcommand: Acts when command ...
0
votes
0answers
22 views

Setting defaults with keyval-interface - do it in the current scope or do it globally?

Assume a LaTeX 2e-macro, be it named \foo, which processes the content of one optional argument via keyval-syntax. E.g., \foo[key1=value1, key2=value2,...,\keyN=valueN] I would also like to have a ...
0
votes
0answers
74 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
0answers
35 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
31 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 ...
0
votes
0answers
51 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 ...
0
votes
0answers
40 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 ...
0
votes
0answers
33 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") ...
0
votes
0answers
19 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} \...
0
votes
0answers
33 views

How to redefine the exponent command

I'm preparing a package that defines a special environment, let us call it myenv, and within the myenv a command, let us call it \mycom that stacks its arguments the one above the other. So \mycom{x}[...
0
votes
0answers
32 views

Removing commands from input to command

I'm trying to create my own command to highlight some changes. I want the command to update a counter, add a line in the contents table and do some changes in the text. So far, I got: \...
0
votes
1answer
36 views

Adding TeX code as a macro in LyX

I am using LyX and I tried adding a macro that includes TeX code but it seems as if it doesn't recognize the \abs command: To be clarified, when adding the following TeX code the file compiles: and ...
0
votes
0answers
34 views

Outputting a custom glossary to a separate file

I'm working on the translation of a German book and have created the following macro so as to link some translated words and expressions to their original, which then I print at the end of the ...
0
votes
0answers
40 views

Shortcut for \begin{equation} - recognized as math by Texmaker

When typing a math report, I want to use my prof's advices: he defines shortcut for equations: \newcommand{\be}{\begin{equation}} \newcommand{\ee}{\end{equation}} This makes it much easier to use, ...
0
votes
0answers
40 views

Preprocess a .tex file and save it as a new file

I have several .tex files that I would like to share with other people. I've included in them (with the command \input) several files with macros that I've written myself. However, I would like to ...
0
votes
0answers
52 views

Pre-define complicated math operators

Problem I am trying to find a easy way to write Rademacher complexity so that I just need to write different index, function and constraint every time. Like defining partial derivative I previously ...
0
votes
0answers
26 views

Using optional argument in closing statement of new environment

The answer 969/29410 showed that it is possible to use optional arguments in environment definitions: \documentclass{article} \newenvironment{hello}[1][world]{\noindent Hello #1, }{Bye now!\\} \begin{...
0
votes
0answers
44 views

Conditional compilation within a macro?

I'm trying to define an environment that is conditionally complied in lualatex. The two solutions I've tried are the following: \documentclass{article} \newenvironment{test}{\ifx\X y \\ }{\else \\ \...
0
votes
0answers
49 views

Customize acronyms usage of first use

So I have a list of acronyms defined with the glossaries package, like such: \newacronym{mac}{MAC}{Medium Access Control} but also some of these: \newcommand{\mk}{Master Key} because the latter ...
0
votes
0answers
51 views

Macro redefinition within sectioning titles does not work in ClassicThesis

MWE #1: \documentclass{scrbook} % KOMA-Script book \usepackage[T1]{fontenc} %\usepackage[style=arsclassica, parts=false]{classicthesis} \begin{document} \tableofcontents \def\aaa{a} \...
0
votes
0answers
51 views

How to use custom command output as lenght?

In order to convince TeX to keep the grid I tried to program a command, that takes a font size switch as parameter and calculates the reminder of the division of the corresponding baseline skip and ...
0
votes
1answer
38 views

Printing labels into file to support editor

I am using the following command to define a custom counter for different things I refer later in the document. \usepackage{cleveref} \newcommand{\customcounter}[2]{% \newcounter{#1} \setcounter{#...
0
votes
0answers
94 views

texstudio cref completion for labels in macros

Is there a way to have completion for cref references for labels defined in a command macro? \newcommand{\midpict}[4]{ \begin{center} \begin{figure}[H] \begin{center} ...
0
votes
0answers
69 views

use of \newcommand in user-written LaTeX package

I've tried to put into a package a LaTeX macro I use all the time in my Beamer slide. Here it is \NeedsTeXFormat{LaTeX2e}[1994/06/01] \ProvidesPackage{icone}[2018/06/20 insert journal icone in beamer ...
0
votes
0answers
48 views

compose string from \newcommand macros

I create a new macro \newcommand\var{test} I would like to use the macro to compose a string, e.g. as in \input{the\varfile.txt} It now looks as if we have a new macro \varfile. How to separate ...
0
votes
0answers
98 views

TeX Live - Names of all standard macros (the one proposed by TeX Live Utility)

Goal I'm working on a Python script that will try to find the packages really used in a (La)TeX file or a piece of a (La)TeX file. I can't just keep the packages indicated via \usepackage because if ...
0
votes
0answers
46 views

pgfplotsforeachungrouped with >2 entries

I'm having trouble understanding why \pgfplotsforeachungrouped is breaking in certain spots. Why does this work: \documentclass{article} \usepackage{pgfplotstable} \def\macroOne#1{ #1 } \...
0
votes
0answers
53 views

expand preprocessor

This is my tex file: \newcommand{\kk}[1]{\left(\, #1 \,\right )} \begin{document} $\kk{a}^2=10$ \end{document} I want to create a new tex file that look like this one: \begin{document} $\left(\, a ...
0
votes
0answers
35 views

One-off redefinition of the section numbering

I use a the article class and have set the following: \renewcommand{\thesection}{\Roman{section}} \renewcommand{\@seccntformat}[1]{{\csname the#1\endcsname}.\hspace{0.5em}} This makes my \section{...
0
votes
0answers
38 views

Trying to change a \chapter macro without success

I am trying to change the word "Capítulo" (portuguese) for "Chapter" with the commands after % but it is not working. \documentclass[ruledheader]{abnt_UFF} %\renewcommand{\chaptername}{Chapter} ...
0
votes
0answers
66 views

Forcing cleverref to use another numbering system

I am fighting with this problem for a while now and all my partial solutions just don't fit together. I have to manage quite a few lists in a latex document and each entry has a certain ID like [X1234]...
0
votes
0answers
55 views

using a variable in two tex documents

I have a file named "main" and other name "other" and I want input data in main file and these data will be processed by external, for example: file main.tex \documentclass{report} \def\name#1 \...
0
votes
0answers
44 views

Relaxing a command's requirement to be run in mathmode (specifically \sage in tikz \draw command)

I would like to be able to build a dynamic tikz picture using some random numbers generated via sage. Presently this seems to fail because tikz doesn't like the mathmode that sage has to be run inside ...
0
votes
0answers
56 views

A macro based on the syntax

I want to define a macro that depends on his syntax, for example \def\macro(#1){code here} \def\macro[#1){different code here} ... \def\macro(#1]{different code here} I saw many way to do this. ...
0
votes
0answers
110 views

Conditional to execute alternative code when error detected

I would like to be able to build a conditional to execute one set of code if the conditional would compile, versus another if the code would generate an error. Take the following code block which ...
0
votes
0answers
60 views

How to dynamically generate function argument signatures using custom API in LaTeX3

In trying to learn more about the details of what is possible with LaTeX, I wanted to see if I could create an API around creating functions. This is what the output function would be, for example: \...
0
votes
0answers
36 views

(Framed) environment blank spaces

Could be a very beginner question, but still. Considering the following: \usepackage{framed} \usepackage{tikz} \usepackage{listings} ... \newcommand{\some}{\textcolor{red}{\lstinline{some}}} \...
0
votes
1answer
165 views

Gnuplottex: Pass latex command to gnuplot script

I want to access and plot the same data from different LaTeX documents (a paper and a beamer presentation) using gnuplottex. The data and the gnuplot script is stored at some individual position ...
0
votes
0answers
63 views

The macros I previously defined no longer seems to work (Tex Studio)

I am using Tex Live and Tex studio. The macros I defined months ago and which were working just fine until this morning seem no longer be working. The macros appear in a pink box and the document ...
0
votes
0answers
57 views

How to Make a newcommand to Give Different Outputs for Displayed Math or Inline Math?

Does any one know how to make a single simple command that gives different outputs for displayed and inline maths \documentclass{article} \usepackage{amsmath} \begin{document} $A^\prime$ \begin{...
0
votes
0answers
48 views

Redefining subsubsection

In book class, subsubsections induce huge spacing before and after and makes the structure too empty for my taste. Hence I would like to redefine it in order to get the one present in amsart for ...
0
votes
0answers
99 views

newcommand in math mode error

I am making a presentation and I need to use the following expression quite a lot, so I made the following new command \newcommand{\extreig}[1][\lambda]{\ensuremath{{#1}_{\mbox{{\footnotesize extr}}}...
0
votes
0answers
52 views

Spot commands in the layout file

I'm searching for a way to highlight some commands in the layout file. I need, in my proofreading work (I'm a typesetter) to quickly spot some kinds of commands like vertical space modifiers or page ...
0
votes
0answers
56 views

Macros to show page number on the right side of the footer

I want to show page number on the right side of the footer. Currently, it's shown in the center of the footer. This is my macros: % Macros to format the page numbering. \def\ps@myheadings{\let\@...
0
votes
0answers
48 views

\isdefempty not working for multiple macros

I am still learning tex. The following example allows me to check if a variable exists, and if it does then prints some text in the PDF. This works great. However, when I add in a href, this appears ...