Articles of macros

Remove space before macro if exist a environment

I create a new macro: \newcommand{\intersection}[1]{% \par\vspace{\baselineskip}% \noindent\textbf{\large\bfseries\sffamily #1}\par} It works perfectly for what I want, but when there is a environment before macro, latex insert two lines: If possible that macro “detects” when exist a figure (or other environments) don’t insert a line break? MWE \documentclass[a4paper]{article} \usepackage{caption} \usepackage{amsmath,amssymb} \usepackage{chemfig} \newcommand{\intersection}[1]{% \addvspace{\baselineskip}% \noindent\textbf{\large\bfseries\sffamily #1}\par} \begin{document} […]

Non-italic \emph, italic biblatex titles

The internal Biblatex \mkbibemph macro defaults to being an alias for \emph (see section 4.10.4 Auxiliary Commands and Hooks in its documentation). It is used with \DeclareFieldFormat to typeset certain fields, especially title, in many bibliography styles. I redefined \em and thereby \emph, however, because I cannot use italics for emphasis in text. Italics are […]

Understanding token expansion

First of all, note that this question is to be regarded as a learning question as I am not looking for a package (I know very well the xparse package). I am attempting to write a macro which has the following usage: \dsee*{text}[optarg] My code is thus the following: \def\md@err{*} \def\@hmno[#1]{% \textsubscript{#1}} \newcommand{\dsee}{\@ifstar\@@dsee\@dsee} \def\@@dsee#1{% \md@err#1\@ifnextchar[\@hmno\relax} […]

Passing an argument with the alignment operator (&) to a macro within another aligned environment

I am trying to write macros for quickly formatting matrices in math mode. Here is a simple, working example: \documentclass{article} \usepackage{amsmath} \newcommand{\pmat}[1]{\begin{pmatrix}#1\end{pmatrix}} \begin{document} \begin{displaymath} M = \pmat{1&0\\0&1} \end{displaymath} \end{document} This also works if used within an aligned environment (a table, align environment, cases environment, etc.): \documentclass{article} \usepackage{amsmath} \newcommand{\pmat}[1]{\begin{pmatrix}#1\end{pmatrix}} \begin{document} \begin{align} M &= \pmat{1&0\\0&1} \end{align} \end{document} […]

How to use \csname … \endcsname with \ref?

I have to get value of a dynamical macro where the index is given by \ref{mymarker}. Is it possible to do? I define a set of macros with a predefined counter ‘mycounter’ as \expandafter\newcommand\csname mymacro\the\value{mycounter} \endcsname{mytext} where ‘mytext’ depends on the value of counter. After that I define a new command \newcommand{\anotherref}[1]{\csname mymacro\ref{#1} \endcsname} the […]

TeX-FAQ: Non-letters in macro names – special-command generator

I had a look at TeX-FAQ on Non-letters in macro names and tried to implement the approach #2. It looks like I’m missing something. When trying to refer later to the new commands the result is not what I expected. \documentclass{standalone} \usepackage{tikz} \begin{document} \newcommand{\DefineNode}[2] { \expandafter\newcommand\csname node-#1\endcsname{#2} } \newcommand{\GetNode}[1]{\csname node-#1\endcsname} \begin{tikzpicture} \def \intra {1} \def […]

About shorthand \frac

It is possible to write \frac 2 4 or \frac \pi 4 to get 2/4 and \pi/4, respectively. However, it is not possible to write \frac \sqrt{2} 2 to get \sqrt{2}/2. Are there consistent rules on how to write shorthand \frac?

luacode and ExplSyntaxOn/Off

I’m trying to build some sort of an interface to a lua matrix module. I’ve navigated a few issues and arrived at something that I felt like I could probably modify to work. Anticipating the need for expl3 functions as some point I wrapped the macro in \ExplSyntaxOn and \ExplSyntaxOff expecting a total catcode disaster. […]

Wrapper for siunitx' \SI macro to automatically split number and unit

Problem I use the siunitx-package to typeset numbers and units with correct spacing etc. There is a command \SI{<number>}{<unit>} for that. However, it would be much easier to write something like \xSI{<number and unit>} and let LaTeX automatically split the number and the unit and call \SI{}{} internally. \xSI{9.81m/s^2} → \SI{9.81}{m/s^2} \xSI{1e-3m} → \SI{1e-3}{m} I […]

\renewcommand and \newcommand for accented letters

I’m using OT1 font encoding, but I would like to use T1 font encoding for glyphs that don’t exist in OT1. To do that, I’m redefining the typical T1 commands so that they automatically choose a T1 encoding. With the commands for accented letters, however, like \’e for é, using \newcommand{\’e} won’t work because \’ […]