New answers tagged

1

Here's a LuaLaTeX-based solution. It defines two fully-expandable "wrapper" macros named \mycmd and \mkfirstuc, which pass their arguments to Lua functions named mycmd and mkfirstuc. The Lua functions perform the actual work of prefixing "an " or "a " to a string and of upper-casing the first character in the string, respectively. % !TEX TS-program = ...


5

Here's an approach with expl3 \documentclass{article} \usepackage{xparse,glossaries} \ExplSyntaxOn \DeclareExpandableDocumentCommand{\indef}{m} { \str_case_x:nnF { \tl_head:f { \tl_lower_case:n { #1 } } } { {a}{an} {e}{an} {i}{an} {o}{an} {u}{an} } {a}~#1 } \ExplSyntaxOff \begin{document} \indef{abc} --- \indef{cde} --- ...


5

This is easy enough using expl3 (there are several possible approaches): \documentclass{article} \usepackage{expl3,xparse} \ExplSyntaxOn \DeclareExpandableDocumentCommand \mycmd { m } { \__mycmd_loop:nN {#1} aeiouAEIOU \q_recursion_tail \q_recursion_stop } \cs_new:Npn \__mycmd_loop:nN #1#2 { \quark_if_recursion_tail_stop_do:nn {#2} { a } ...


5

I'm not sure if you really want this; however, here it is. \documentclass{article} \usepackage{amsmath} \usepackage{unicode-math} \ExplSyntaxOn \NewDocumentCommand{\defineoversetchar}{m} { \clist_map_inline:nn { #1 } { \kasper_define_overset_char:n { ##1 } } } \cs_new_protected:Nn \kasper_define_overset_char:n { \cs_new_protected:cn { ...


2

It's a parbox and boxes never break however to avoid spurious white space you are missing one % at the end of the penultimate line. \newcommand{\totalpoints}{% \parbox{\linewidth}{% \leavevmode\raisebox{-0.5ex}{\llap{\textbullet}}\!\hrulefill\\[-0.825ex]% \null\hfill\bfseries Total Points: \total{totalpoints}~~\rlap{\rule{0.4pt}{3ex}}% }% } ...


7

You want to expand mychoice before calling \selectpet so: \expandafter\selectpet\expandafter{\mychoice}


6

OpenType support in TeX as of when I first wrote xfrac in early 2004 was basically non-existent - XeTeX hadn't even been released back then. Therefore, the package was never designed with that in mind. Besides, the fundamental purpose was to provide a way to write nice fractions for fonts that didn't include them. The package could very likely be made ...


2

I wonder about the \string#1 inside. The new command inside can be constructed with \expandafter\NewDocumentCommand\csname #1\endcsname{...}{....} i.e. the name of the new sequence must be constructed first with \expandafter (first the name is given, then \NewDocumentCommand comes into action). The same approach has to be taken for the traditional ...


4

You have to construct the macro name with \csname A#1\endcsname. In fact, a lot of package or class code makes use of this \csname ...\endcsname construction and it's not restricted to LaTeX, since both macros are TeX primitives actually. Please note: \AA is already defined, providing a Scandinavian character, i.e.s something like Å (But since the command ...


2

\documentclass[pagesize=pdftex,DIV=16]{scrartcl} \usepackage{xcolor} \usepackage{hyperref} \newsavebox\TBox \begin{document} \begin{Form} \section*{Principal Investigator} \sbox\TBox{Full Name: }% \TextField[backgroundcolor=gray!30,borderwidth=0,width=\dimexpr\linewidth-\wd\TBox]{Full Name:}\\[1ex] ...


1

This does not answer your question, since you are making your form with the hyperref Form environment, which I don't understand. If this was as simple as filling a line with a grey box it would be pretty easy, after the model of LaTeX's \hrulefill. Perhaps this information might lead to a solution. \hrulefill in LaTeX uses the TeX primitives \leaders and ...


3

Here I create \altfrac{}{}. It does not require fontspec, it obeys math mode, its font is larger than that of \sfrac, the denominator lies on the baseline, while the top of the numerator I tries to lay at the top of the normal text font. The numbers are presented in \footnotesize. The slash is a horizontally stretched / to give it more of the fractional ...


0

There may be some other standard solutions but a quick hack is to use the rule command. Give this a try and it might work albeit it isn't the most elegant solution available. Play around with the width and height parameters. \rule[depth]{width}{height} Cheers


1

You can use minipage to generate a separation as reqested: \documentclass{article} \usepackage[T1]{fontenc} \begin{document} \begin{minipage}{0.20\textwidth} %left column Tech \end{minipage} % \hfill\vline\hfill % \begin{minipage}{0.70\textwidth} %right column lot more text multi line wonderful \end{minipage} \end{document} Best, Frank


2

Christian has shown what you could do instead but to explain the error @ is not a letter in the main document so \let\@var\@empty does \let\@=v then typesets ar\@empty producing the paragraph text arvempty (which you don't see as later errors prevent a pdf being made. Then \newcommand{\append}[1]{ \xdef\@var{\@var #1} } defines \append to typeset ...


3

You're missing \makeatletter...\makeatother pairs -- those are necessary due to \@ as macro (starter) name. If the 'string' macro should not be indicated as internal (\@.... are internally 'hidden) choose another name, like \mystringvar, this will remove the issue with \makeatletter...\makeatother \documentclass{article} \begin{document} \makeatletter ...


9

(Admittedly, the example with \color) could be achieved without this, but let us assume \mycmd is more complex for the real case and not a toy 'theory';-)) Collecting the environment body is easiest with environ package and its \NewEnviron command and \BODY. \documentclass{article} \usepackage{xcolor} \usepackage{environ} \usepackage{blindtext} ...


1

For completeness, you could also define the macro as \def\naive#{na\"{\i}ve} which will require that it be followed by {} when ever it is used. For example, the \naive{} approach will work whereas the \naive approach will raise an error which says Use of \naive doesn't match its definition.. See page 204 of The TEXbook for details. Also, this answer may ...


6

*This is a summary answer, highlighting the benefits and drawbacks for the different techniques available to preserve spaces following a control word. Conceptually, this is intended for LaTeX implementations where the control word does not accept arguments, expands to simple, possibly formatted, text, and is used primarily in prose. Background: The TeX ...


0

The solution seems much simpler: \documentclass[letterpaper, 12pt]{article} \usepackage{tasks} \NewTask{subquestions}[\subquestion] \begin{document} \begin{enumerate} \item First question \begin{subquestions} \subquestion First subquestion \subquestion Second subquestion \end{subquestions} \item Second question \item Third question ...


5

It's possible with collcell: \documentclass{article} \usepackage{longtable} \usepackage{collcell} \newcommand{\cutlongemail}[1]{% \sbox0{#1}% \ifdim\wd0 > \linewidth \docutlongemail#1\relax \else #1% \fi } \def\docutlongemail#1@#2\relax{#1@\newline#2} \begin{document} \begin{longtable}{ p{0.3\linewidth} ...


4

\left[....\middle|....\right\]


4

A standard application of \DeclarePairedDelimiterX: \documentclass{article} \usepackage{mathtools,amssymb} \newcommand{\Econd}{\operatorname{\mathbb{E}}\EcondX} \DeclarePairedDelimiterX{\EcondX}[2]{[}{]}{% #1\nonscript\;\delimsize|\nonscript\;#2% } \begin{document} Some examples are \begin{align*} &\Econd{X_t}{X_s}\\ %normal look ...


2

And for contrast, a rather more low-level approach is as follows: \documentclass{article} \newcommand\teststart{% \begingroup % start a group \bfseries % make the content bold, for demo purposes \let\testend\endgroup % within this 'environment' (only), % \testend acts to close the group } \begin{document} ...


3

A higher level possibility is with xparse: \usepackage{xparse} \NewDocumentCommand{\teststart}{+u{\testend}}{% do something with #1% } The + allows the argument to contain blank lines.


4

You can define an environment this way: \newenvironment{test}{<commands to execute at beginning}{<commands for end} You use the environment like this: \begin{test} bla-bla-bla \end{test} If you want to apply a command to the contents of the environment as a whole, you can do this with the environ package. The macro \BODY stands for the whole body ...


7

This is possible using TeX's \def, where you require a specific argument text. The argument text includes both the specific sequence to be replaced, as well as the arguments in the form #X (where X is a number from 1 through 9): \documentclass{article} \def\teststart#1\testend{left-#1-right} \begin{document} \teststart this is something \testend ...


2

With \newcommand the replacement text is already tokenized according to TeX's rule, so you need to use \csname: \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[runall=true]{pythontex} \usepackage{etoolbox} % defines lists and their operations \newcommand{\createresult}{\pyc{result = ("Peter P", "Charlie D")}} ...


4

Do it the hard way. However, I heartily recommend not using \ensuremath: put math symbols in math mode. \documentclass{article} \newcommand{\UCmath}[1]{% \begingroup \ucmathlist\MakeUppercase{#1}% \endgroup } \newcommand{\ucmathlist}{% \def\alpha{\mathrm{A}}% \def\beta{\mathrm{B}}% \let\gamma=\Gamma \let\delta=\Delta ...


7

Here's a Metapost alternative. I like the fact that in MP you can make a macro that returns a path that you can assign to a variable, and then pass it to other commands like draw, reverse, fill and apply transformations to it like shifted, rotated, etc. prologues := 3; outputtemplate := "%j%c.eps"; % Make a random ellipsoid with semiaxes a,b and r ...


10

As others have mentioned the pic is a useful way to go. Note, that if the loop is drawn using individual paths then a fill is not possible. Conversely, if the loop was drawn as one path then it would not be possible to get arrows on the individual segments of the loop without redrawing individual segments, unless a decoration is used: ...


15

You can use a pic. The interface here isn't that good, but I think it works. To just add a black shape use e.g. \pic at (0,0) {randomblob};. As set up, randomblob has four key-value arguments, used as randomblob={<key>=<value>}. They are edgecolor - the color of the line, black by default. fillcolor - fill color. If not specified, no filling is ...


4

Typically that's the way TeX primitives react. From the TeXbook (Chapter 3: Controlling TeX, p 10): How can a person distinguish a TeX primitive from a control sequence that has been defined at a higher level? There are two ways: (1) The index to this manual lists all of the control sequences that are discussed, and each primitive is marked with an ...


8

\jobname is not a macro (essentially it's not defined with \def) it is an expandable primitive that expands to the filename. You can make a macro with the same expansion \edef\xjobname{\jobname} *\show\xjobname > \xjobname=macro: ->texput. so \xjobname has the same expansion as \jobname but they have different \show behaviour and crucially they ...


1

You can use classic plain TeX approach because ConTeXt knows plain TeX macros and TeX primitives: \newcount\symbolnum \def\putsymbols[#1][#2]#3{% \symbolnum=0 \loop \advance\symbolnum by1 \color[red]{#3}% \ifnum\symbolnum<#1 \repeat \it \loop \advance\symbolnum by1 \color[blue]{#3}% ...


1

If you're free to use LuaLaTeX, you could use it as a preprocessor to replace all instances of s2 with \ensuremath{\textnormal{s}^2} "on the fly". The code given below works by assigning the function that performs this replacement to the process_input_buffer callback, which operates before TeX begins its usual processing. That said, I think you're better ...


3

The conventions holding between \ExplSyntaxOn and \ExplSyntaxOff are, essentially: spaces and end-of-lines are ignored (but not in the middle of a control sequence name, of cours) _ and : can (and should) be part of control sequence names, so they have category code 11 (letter) ~ is the same as an ordinary space token A consequence of this is that _ ...


2

If, for some reason, you need to use a subscript inside expl3 syntax, you can always use \sb \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\fooT}{mm}{#1\sb{#2}} \ExplSyntaxOff


5

I assume that the O.P. has \ExplSyntaxOn...\ExplSyntaxOff as a wrapper around the definition of \fooT. This will change the catcodes of course and _ is interpreted differently. If none of the expl3 syntax (e.g. think of \cs_new:N etc.) is needed, don't use \ExplSyntax.... The \NewDocumentCommand is sufficient for this! \documentclass{article} ...


8

Taking a file, xyz.tex, I just used as an answer to another question \documentclass[12pt]{report} \usepackage{array} \usepackage{amsmath} \begin{document} \begin{tabular}{| >{$}c<{$} | c | c | c | c | c | c |c |} \cline{2-8} \multicolumn{1}{c|}{}&\multicolumn{7}{c|}{\rule{0mm}{0.4cm}{figure1 put here}}\\ \hline \rule[-.5cm]{0mm}{1.2cm} x & ...


3

Not really 'high-level' but since xparse is used anyway and SplitList is expl3 anyway: The \convert command uses the first starred argument for the f>g>h splitting and the third argument is for reversal of the order. It uses a \seq_... variable and splits the input by ; into tokens and glues them together (or replaces effectively ; by >) and ...


4

It is often easier to use a lua-based solution than to figure out TeX arithmetic. \define\PutSymbols{\dodoubleempty\doPutSymbols} \def\doPutSymbols[#1][#2]#3{\ctxlua{userdata.putsymbols(#1, #2, [===[#3]===])}} \startluacode userdata = userdata or {} function userdata.putsymbols(n, m, s) for i = 1,n do context.color({"darkred"}, s) end ...


5

Assuming I have understood what you're after... Here's a suggestion that may do what you want: \def\PutSymbols{\dodoubleempty\doPutSymbols} \def\doPutSymbols[#1][#2]#3{% \iffirstargument \dorecurse{\the\numexpr #1\relax}{\color[darkred]{#3}} \else \dorecurse{1}{#3} \fi% \ifsecondargument \dorecurse{\the\numexpr ...


1

There is no “if token list begins with” predefined function. You can build it easily with l3regex: \documentclass{article} \usepackage{xparse,l3regex} \ExplSyntaxOn \DeclareExpandableDocumentCommand{\whatever}{} { \tl_use:N \g_macmadness_whatever_tl } \tl_new:N \g_macmadness_whatever_tl \cs_generate_variant:Nn \regex_match:nnTF { nV } ...


0

\documentclass[a4paper]{article} \newcommand\test[2][]{#2\ifx\relax#1\relax\else\textsuperscript{#1}\fi} \begin{document} The player ended as no.~\test{1} and her friend came ind \test[nd]{2}. \end{document}


3

I'd suggest an alternative interface using * (say): \documentclass{article} \usepackage{fmtcount} \makeatletter \newcommand{\@test}[1]{#1} \newcommand{\@@test}[1]{\ordinalnum{#1}} \newcommand{\test}{\@ifstar\@test\@@test} \makeatother \begin{document} \test{1} \test*{1} \test{2} \test*{2} \test{11} \test{12} \test{21} \end{document} The above ...


8

With xparse the feature can be done easily with the g optional argumen t specifier, but optional arguments should be done with [...], i.e. use o rather, in my point of view! \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\test}{mg}{#1\IfValueT{#2}{\textsuperscript{#2}}} \begin{document} The player ended as no.~\test{1} and her friend ...


2

as cfr says, no calculation is necessary, but if #2\columnwidth works then #2 must be a factor but \numexpr needs an integer and \dimexpr needs a length so neither can calculate (1-#2-#4) \makebox[\textwidth]{% \hfill \includegraphics{...}% \hfill \includegraphics{...}% \hfill} should do what you want. In general you can do \makebox[\textwidth]{% ...


1

You need \edef; the step \edef\X{\Alph{ctr}} is not needed. \documentclass{article} \newcounter{ctr} \loop \stepcounter{ctr} \expandafter\edef\csname S\Alph{ctr}\endcsname{\noexpand\mathcal{\Alph{ctr}}} \ifnum\thectr<26 \repeat \begin{document} $\SA$ \end{document} An \edef free solution: \documentclass{article} \count255=`A ...


1

In order to patch an environment such as figure* you can do \expandafter\patchcmd\csname figure*\endcsname{....}{...}{}{} This method is ineffective with commands such as \section*, which are defined in a completely different way. On the other hand, if you just want to add \centering to all floats, you can just add \centering to \@floatboxreset: ...



Top 50 recent answers are included