Tag Info

New answers tagged

4

That would take a lot of work. It would be easier to use a two macro approach. I usually do this independently of \chapter using \chapterprecis. If you wanted it directly into the chapter style it might be better to use an approach like \setchapterdesc{....} \chapter{....} and then let the chapter style use the macro that the imaginary macro ...


3

There are a number of ways, depending on what you're after: \documentclass{article} \setlength{\parindent}{0pt}% Just for this example \begin{document} \let\TextBF\textbf% Copy definition of \textbf into \TextBF \textbf{textbf}\par \TextBF{TextBF} \let\textbf\texttt% Change original \textbf to now be equivalent to \texttt \textbf{textbf}\par ...


9

The conditional \ifx does no expansion and it compares the next two tokens. So in your test it compares \myarg with the first token in #1. Therefore the test will be always false, because #1 is the name of a section level counter. Adding \expandafter before \ifx would not help, even adding braces around #1: \expandafter\ifx\myarg{#1}\mytest would become ...


2

Try adding the following code to your preamble: \makeatletter \renewenvironment{@tufte@margin@float}[2][0pt]{% \FloatBarrier% process all floats before this point so the figure/table numbers stay in order. \begin{lrbox}{\@tufte@margin@floatbox}% \begin{minipage}[t]{\marginparwidth}% top-aligned minipage \@tufte@caption@font ...


5

My guess: \newpage is what you are looking for. It starts a new page, if there is something. Otherwise \newpage does not cause a page break.


3

You need \meaning, something like \documentclass{article} \def\foo#1>{} \newcommand\showcase[1]{% \def\tmp{#1}% \texttt{\expandafter\foo\meaning\tmp} #1} \begin{document} \showcase{$\alpha$} \end{document}


0

Seems like mdframed provides what you want … \documentclass{article} \usepackage{xcolor} \usepackage{mdframed} \newmdenv[% backgroundcolor=yellow!80!black, hidealllines=true ]{leftside} \usepackage{lipsum} \begin{document} \lipsum[1-4] \begin{leftside} \lipsum[1] \end{leftside} \lipsum[1-2] \end{document} The package has lots of options ...


4

If your \newcommand{\HelloWorld} is the last activity before \begin{document} and there are no anothers " in your real code, you should prepend before this command: \catcode`\"=13 and you needn't to change your definition. The reason was answered by egreg. You need to have the " active at the time of definition of the \HelloWorld.


5

The package csquotes performs \MakeOuterQuote{"} by making " active, but it postpones the setting \AtBeginDocument. So, when your \newcommand{\HelloWorld}{...} is processed, the " characters in the replacement text are normal (non active) characters. If you try adding \show before the first " in the definition, compilation will stop with > the character ...


9

\twoheadleftarrow and \twoheadrightarrow can be combined to \twoheadleftrightarrow: \documentclass{article} \usepackage{amssymb} \newcommand*{\twoheadleftrightarrow}{% \twoheadleftarrow \mathrel{\mkern-15mu}% \twoheadrightarrow } \begin{document} \[ \twoheadleftrightarrow \scriptstyle \twoheadleftrightarrow \scriptscriptstyle ...


4

We need expanable switch statement. When egreg use \ExplSyntaxOn ... \ExplSyntaxOff then I can use NormalTeXSyntaxOn ... NormalTeXSynatxOff in my example, because NormalTeXSyntax is more natural than whatever else syntax. It is syntax of TeX program itself. If you know this syntax well then you needn't to know any other syntax. I hope that somebody will ...


8

The argument to \color (when called without the optional color space argument) must directly expand to a string of characters, which should be a color name (or a tint specification if xcolor is used). There are several expandable switch statement available. I suggest one using expl3: \documentclass{article} \usepackage{xparse} \usepackage{color} ...


2

If you do not need a table of contents you can delete the lines for the toc redefinition. However a solution with a special macro like \Ssection} maybe a better choice, then \ţableofcontents hasn't to be redefined: \documentclass[12pt, a4paper]{article}% \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage{xcolor} ...


3

There's a numberless key (to be used with name) that does the job: \documentclass[12pt, a4paper]{article}% \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \usepackage[x11names]{xcolor} \usepackage[explicit]{titlesec}% \titleformat{\section} {\ttfamily\Large\bfseries\color{red}} {\thesection} {1em} {#1} ...


4

the question isn't very clear but \newcomamnd\macroX[1]{} appears to do what you ask.


10

I'm not sure I understand the problem. Here's how it's treated with the macro \@addpunct made available by amsthm: \documentclass{article} \usepackage{amsthm} \makeatletter \newcommand{\macroaddingperiod}[1]{% \emph{#1}\@addpunct{.}% } \makeatother \begin{document} Here we use \macroaddingperiod{on some text} Should we add \macroaddingperiod{a period ...


3

The error you get Use of \csname doesn't match its definition is a clear sign that something has gone wrong in a definition, because it means you have redefined \csname. This happens in \expandafter\protected@edef\expandafter\csname\tcsa\endcsname{% \expandafter\csname\tcsb\endcsname} because the first \expandafter expands the second wich expands ...


3

The problem is the line \expandafter\protected@edef\expandafter\csname\tcsa\endcsname{\expandafter\csname\tcsb\endcsname}% Here, you are expanding \tcsa (which you don't actually need to do), but not expanding \csname before \protected@edef. The result is you redefine \csname: a Bad Thing! You need instead ...


5

i) A tabular stack does the work almost everywhere there are ordered rows and columns of symbols, but a scalebox won't compile inside it. \scalebox should work there. ii) A raisebox seems to work well in some cases, but it won't compile when placing math mode font size commands inside it, and in similar instances. a \raisebox forms a ...


2

I suggest using eso-pic which allows you to add content at page shipout using a number of different macros: \documentclass{article} \usepackage{lipsum} \usepackage{tikz,eso-pic} \usetikzlibrary{calc} \pagestyle{empty} \newsavebox{\textone} \newsavebox{\texttwo} \newenvironment{topr}{% \begin{lrbox}{\textone}% \begin{minipage}{11cm}% \raggedleft ...


7

There are 256 internal codes in classical TeX and pdfTeX and you can set arbitrary subset of them as letters (catcode 11). Then such characters can be used in control sequences. There are many thousands of internal codes (from Unicode) possible in LuaTeX and XeTeX. If you set (for example) cyrillic as letters then you can use them in control sequences. ...


1

You need an \immediate version of \write (see Writing \\ to a File). The \protected@iwrite command has one argument more, where to give settings that are applied when writing. For writing a literal ~ you need to make it (temporarily) equivalent to \relax: \documentclass{article} \usepackage{amsrefs} \usepackage{xpatch} \makeatletter % get a copy of ...


0

Based on your description in the question, this solution proposes a parallel minipage structure to place text and image side by side with adjustbox package. For alignment c(enter) can be changed to b(ottom) t(op). Remove the [demo] option in the graphicx for real implementation. Code \documentclass[]{article} \usepackage[show frame,paper ...


8

The environment form of \sbox is environment lrbox. Environment minipage can be used instead of the command \parbox. Environment flushright is not necessary, because there is the command form \raggedleft. \documentclass[a4paper]{article} \usepackage{lipsum} \begin{document} \newsavebox{\textsix} \newenvironment{bottomr}{% \begin{lrbox}{\textsix}% ...


3

Following some guidelines from How can I collect the contents of a LaTeX environment in a macro without the grouping?, here is an environ approach: \documentclass{article} \usepackage{lipsum,environ} \newsavebox{\textsix} \NewEnviron{bottomr}[1][11cm]{% \expandafter\gdef\expandafter\envBODY\expandafter{\BODY}% Store body ...


4

You could use \@namedef and \@nameuse, just by providing aliases; but this wouldn't trap errors. Here's an emulation of \newcommand and \renewcommand (no *-version): \newcommand{\newlcommand}[1]{\expandafter\newcommand\csname#1\endcsname} \newcommand{\renewlcommand}[1]{\expandafter\renewcommand\csname#1\endcsname} \makeatletter ...


3

I have no idea what the cjk package does but you can use: \makeatletter \protected@xdef\bor{\faa}% doesn't fail in \edef-ining \bor as 四 \makeatletter and also for the other \edef


5

You just need \newcommand{\gsubselector}[1]{$s_{#1}$} because a call such as \gsubselector{a,i} will make a,i as the only argument to \gsubselector, so the macro substitution will give $s_{a,i}$ as required. However, I don't think this is a good definition. In your code snippet you type ... \gsubselector{a,i} : \gsubselector{b,j} there is ... ...


1

Try \newcommand\gsubselector#1{\expandafter\GSUBelector#1!!} \def\GSUBelector#1,#2!!{\ensuremath{s_{#1,#2}}} If it doesn't help create a complete example.


4

Showing three possibilities: The first as you desired, the second with better semantic and the third without an extra macro, as it is not that much to type. \documentclass{article} \usepackage{xcolor} \newcommand{\gray}[1]{\textcolor{gray}{#1}} \newcommand\Edit[1]{\textcolor{gray}{(#1)}} \begin{document} ``All writers \gray{(will have to)} edit their ...


0

No, it isn't safe. \SS may come from a transformation of \ss (lowercase ß) to uppercase in a running headline. When you redefine it, and by bad chance a German sharp s is in your chapter or section title, the running headline may have an unexpected look. Followup errors like "missing $ inserted" may occur too, depending on your re-definition of \SS.


2

Concerning the safety of re-defining command \SS (which is the capital of "ß") in order to shorten the command \mathcal{S}, @egreg said: "Not really safe: your bibliographic data might contain a ß that in turn might be capitalized: the final result would be at least puzzling." That is definitely true, so I've decided to follow the suggestion given by ...


5

If you want to see, what a command is used for, you can use the \show macro: % arara: pdflatex \documentclass{article} \begin{document} %\show\cS \show\SS \end{document} This will show: \SS=macro: ->\T1-cmd \SS \T1\SS . l.7 \show\SS Ok, this information is not so cool, but you can see that is has something to do with the T1 encoding and you see ...


9

TeX has three main modes horizontal, vertical and math with math split into display and inline. So the question is really what commands are allowed in display math. Basically vertical mode commands are not allowed (with the exception of \halign, in the special case that it is the only thing in the display) so for example \begin{equation} \vskip2in produces ...


3

Why not use keys? That way you can have practically as many parameters as you would like. Of the many ways you could do this, here's one: In the preface you could have \usepackage{pgfkeys} \def\mycaption{default caption} \def\mylabel{default label} \def\myfigwidth{0pt} \def\myfigheight{0.05} \pgfkeys{/jotagah/myfig/.cd, caption/.store in=\mycaption, ...


12

The general form of \newcommand is \newcommand\commandname[number of arguments][value of optional argument]{code} (Most of the time there won't be an optional argument, in which case this is omitted.) The arguments are given as #1, #2 etc in code. To define your \brat command you would write \newcommand\brat[2]{[\![#1,#2]\!]} You then use this macro ...


4

You can define a myalgorithm environment (you can call it anything you want) that does this. If you add \newenvironment{myalgorithm}[2] {\begin{algorithm}\begin{algorithmic}\Procedure{#1}{#2}} {\EndProcedure\end{algorithmic}\end{algorithm}} you can use this in your document as \begin{myalgorithm}{Sum}{100} \State abcd \end{myalgorithm} The two ...


1

After reading a bit about the pains involved in forcing *TeX to expand protected commands, I've changed my approach and used the BiBTeX facilities. The following code contains three command sets - one to print out the raw URL, one to format and link the URL using \url and one to create a \href hyperlink with some arbitrary text. \documentclass{article} ...


6

If you're using LuaTeX or XeTeX as engines you surely can define \神 to do that task. Of course you must remember to have a nonletter after \神 or to change the category code of 神 to 12. What happens with pdfTeX as engine? That \newcommand would give an error: ! LaTeX Error: Missing \begin{document} because \newcommand can't define macros with parameter ...


7

run with xelatex or lualatex \documentclass{article} \usepackage{ruby} \renewcommand\rubysep{.05ex} \renewcommand\rubysize{0.2} \usepackage{fontspec} \setmainfont{Arial Unicode MS} \newcommand\神{\ruby{神}{かみ}} \begin{document} \神 \end{document}


3

It seems strange to define \color as a macro that doesn't have anything to do with setting a colour attribute. The best option here is to remove this definition by adding \let\color\relax before loading the color package. Letting a macro to \relax frees it up, almost like it has not existed before.


3

I am still a trial-and-error programmer when it comes to \expandafter. But one thing to keep in mind is it expands tokens which are either characters or control sequences. So if you want to expand a bunch of tokens at once, out of order, it's easiest to put them in a macro. In this case you want to expand the entire optional argument setlist={\names} at ...


1

use \expandafter\addbibresource\expandafter{\myPath biblio.bib} or define \edef\myFile{\myPath biblio.bib} \addbibresource{\myFile}


3

Here's an application of expl3: for splitting I cycle the requested number of times through the input string, picking up the items corresponding to the cycle and forming a sequence; for rebuilding it's just the reverse: I cycle over the sequence elements picking up the first element, the second one and so on from each item. \documentclass{article} ...


7

If I understand your wish, you need to use the following macros: \newcount\tmpnum \def\sedef#1{\expandafter\edef\csname#1\endcsname} \def\expandcsname#1{\expandafter\ifx\csname#1\endcsname\relax \else \csname#1\endcsname\fi} \def\brk#1#2#3{\bgroup\def\brkLines{#2}\ifx+#1\tmpnum=0 \brkA#3{}% \else\tmpnum=1 ...


4

Here's my take; it is assumed that \@nil doesn't appear in the expansion of the second argument. \documentclass{article} \makeatletter \def\TrimBraces#1#2{\expandafter\TrimBraces@aux#2\@nil{#1}} \def\TrimBraces@aux#1\@nil#2{\def#2{#1}} \makeatother \def\a{Test} \TrimBraces\x\a \show\x %-- should be ->Test \def\b{{Test}} \TrimBraces\x\b \show\x %-- ...


6

My solution is only a little alternative to David's solution. The main point is the same: TeX removes outer braces from separated parameter if they exist: \def\aa#1\separator{...} \aa {text}\separator -- #1 is text \aa {text}b\separator -- #1 is {text}b And my solution: ...


6

\documentclass{article} \usepackage{etoolbox} \begin{document} \def\TrimBraces#1#2{\expandafter\zzz\expandafter#1\expandafter{\expandafter\zz#2\zz}} \def\zz#1\zz{#1} \def\zzz#1#2{\expandafter\def\expandafter#1\expandafter{#2}} \def\a{Test} \TrimBraces\x\a \show\x %-- should be ->Test % OK \def\b{{Test}} \TrimBraces\x\b \show\x %-- should be ->Test ...


3

thanks to @David Carlisle 's comment Macros: { xspace: '', ensuremath: '' } did the trick.


5

A feature of \foreach is that it performs each cycle in a group; its main purpose was to add paths or nodes to a tikzpicture being built and this operation is indeed global. Doing \globaldefs=1 is not a good workaround, because \newcommand performs several assignments that you really don't want to be global. You can look at \global\renewcommand equivalent ...



Top 50 recent answers are included