New answers tagged

0

The following does with horizontal and vertical leaders. Drawbacks: Page-breaks are not possible. As the dotted lines are drawn as vertical leaders, vertical skips in the left side other than \baselineskip are not taken into account. \documentclass[12pt]{book} \usepackage[paperwidth=21cm,paperheight=29.7cm,top=2.5cm,bottom=2cm,left=2cm,right=1.5cm]{...


1

It's easy with expl3: \documentclass{article} \ExplSyntaxOn \seq_new:N \g_mrclng_coeffs_seq \NewDocumentCommand{\coeff}{m} { \seq_if_in:NnF \g_mrclng_coeffs_seq { $#1$ } { \seq_gput_right:Nn \g_mrclng_coeffs_seq { $#1$ } } c\sb{#1} } \NewDocumentCommand{\printcoeffs}{} { \seq_use:Nn \g_mrclng_coeffs_seq {,~} } \ExplSyntaxOff \begin{...


0

There are many ways to do it. Here's a simple one using minipage: \documentclass[12pt]{book} \begin{document} \begin{minipage}[t]{\linewidth} \begin{minipage}[t]{0.4\linewidth} \textbf{Example 1.} Lorem ipsum dolor sit amet consectetuer Proin Curabitur condimentum vel Vivamus. Cursus dui vitae et facilisis Mauris sociis ...


0

I recently implemented this in my own thesis based on answer provided by @egreg. However, I realized that referring back to a specific page will be a bother for most people. Thus I implemented it in a way that each page has two different numbers in it. I have Arabic numerals at the top right/left (for odd/even numbered pages) (based on answer to this post) ...


0

Although you don’t say what you’re trying to do, you might have an XY-problem. That is, if your actual goal here is to be able to display Assamese numerals that show as ASCII digits in your source, there are simpler ways to do it. This works in LuaLaTeX: \documentclass{article} \tracinglostchars=3 % Halt if a font cannot display a glyph. \usepackage[...


0

You have to localize the font change: \def\mapcommand#1{{\mapfnt\xxconvert#1@}}% <-- add braces! You can also consider this simpler implementation: \documentclass{article} \usepackage{fontspec} \setmainfont{Times New Roman} \newfontface\mapfnt{Charis SIL} \ExplSyntaxOn \NewDocumentCommand{\conversiontable}{m} { \tl_set:Nn \l_israt_convert_table_tl {...


1

You can use also gensymb package or siunitx as this example without to declare a predefinite command named \deg. \documentclass[12pt]{article} \usepackage{amsmath} \usepackage{siunitx} \usepackage{gensymb} \begin{document} Your angle is \ang{350} (siunitx package) or 350{\degree} (gensymb package). \end{document} The MWE work also in math-mode: $\ang{350}$,...


1

The problem is that the effects of \renewcommand (and \newcommand) are local and \begin…\end creates a group so the \renewcommand will no longer be in effect when the group ends. There are two possible solutions. Drop down to TeX primitives and write instead, e.g.,¹ \NewDocumentCommand{\loigiai}{m}{\gdef\loigiaiend{\par #1\gdef\loigiaiend{}}} note that I ...


1

Sorry to be late to the party. Anyway, the g and G argument specifiers are deprecated. The most natural syntax is \Set{A} or \Set{A | B} which is even easier to type than $\Set{A}{B}$. \documentclass{article} \NewDocumentCommand{\Set}{ >{\SplitArgument{1}{|}}m }{\SetAux#1} \NewDocumentCommand{\SetAux}{mm}{% \bigl\{% #1% \IfValueT{#2}{\bigm|#2}% \...


0

You can create two macros with the different parameter counts (and name) and invoke them within a composite macro with the desired name. Inside the new macro, call one of the two macros based on the number of parameters passed using \IfNoValueTF. \documentclass{article} %Import xparse for \IfNoValueTF \usepackage{xparse} %Define behavior of the command ...


1

A bit off-topic, however: Fahrenheit are not standard unit, instead it is correct to use Celsius degrees. If you for some reason persist to use it, than is sensible to define them as part od siunitx package: \documentclass{article} \usepackage{siunitx} % <--- \DeclareSIUnit{\fahrenheit}{^\circ\mkern-1mu\mathrm{F}} % <--- \begin{document} ...


3

With \newcommand, I get ! LaTeX Error: Command \deg already defined. Or name \end... illegal, see p.192 of the manual. which I'm assuming you ignored when running with that version of the command. \deg is one of the text operator symbols provided by LaTeX. It's used in graph theory to say things like ∑v ∈ V deg(v) = 2|E| When you ran past ...


0

It's very easy with expl3, that's included in the LaTeX kernel since 2020-10-01 (if you have an earlier release you need to add \usepackage{xparse}). \documentclass{article} \ExplSyntaxOn \seq_new:N \l_srour_list_seq \NewDocumentCommand{\addtolist}{mm} { \seq_put_right:Nn \l_srour_list_seq { \item[#1] #2 } } \NewDocumentCommand{\uselist}{} { \...


1

Does the following code provide what you have in mind? \RequirePackage{xparse} \documentclass{article} \newcommand\ItemContainer{}% \NewDocumentCommand\ResetItemContainer{}{% \gdef\ItemContainer{}% }% \makeatletter \newcommand\AddtoItemContainer[2][]{% \@bsphack % use \xdef .. \unexpanded to avoid hash-reducing within \ItemContainer's definition. \...


1

The first big problem with the OP code was redefining \list, which is widely used code used to make a variety of lists, such as the description environment. Oops. So I renamed it \llist, so as to leave the list-making \list intact. Then, I also used \g@addto@macro rather than an \edef to build the list items, because I felt it was a safer way to proceed. \...


6

While this sort of mimics the listofitems usage syntax, it allows a different form of input other than a simple list, which can be non-sequential if desired. \documentclass{article} \makeatletter \newcommand\setaside[1]{% \def#1[##1]{% \csname\expandafter\@gobble\string#1[##1]\endcsname}} \def\define#1[#2]#3{% \expandafter\def\csname\expandafter \@...


0

Base on the @modnar's suggestion. Thank you very much for your helps! \documentclass[12pt]{article} \usepackage{etoolbox} \newbool{blbt} \newbool{blvd} \newif\ifoutput \newcommand{\classify}{\outputtrue} \newcommand{\classifyp}{ \ifoutput{ The environment below is \ifbool{blvd}{Example}{\ifbool{blbt}{Problem}{Wrong}} }\fi } %%%=======================...


1

If you don't mind your command \classify and your environments bt and vt to have a non-optional argument, then you can use the package zref and have the environments bt and vt place referencing-labels for properties blvd and blbt the command \classify extract values of properties from these referencing-labels: \documentclass[12pt]{article} \usepackage{...


6

Ad question 1: I was wondering if there are any clever workaround for including a number in a custom macro name? I'm working with a platform that integrates LaTeX with a computer algebra system, and frequently have variables such as a[1], a[2] etc that I have to assign to tex commands. Right now, the most functional solution I've found is using Roman ...


1

\documentclass[12pt]{article} \newif\ifblbt \newif\ifblvd \newenvironment{bt} {\blvdfalse\blbttrue{\bfseries\classify\par}} {} \newenvironment{vd} {\blvdtrue\blbtfalse{\bfseries\classify\par}} {} \newcommand\classify{The below environment is \ifblvd Example\else\ifblbt Problem\else Wrong\fi\fi} \begin{document} \begin{bt} Contents PPP \...


4

How about this? \documentclass[12pt]{article} \usepackage{etoolbox} \newbool{blbt} \newbool{blvd} \newcommand{\classify}{The environment below is \ifbool{blvd}{Example}{\ifbool{blbt}{Problem}{Wrong}}} %%%======================= \newenvironment{bt}{\global\setbool{blvd}{false}\global\setbool{blbt}{true}{\bfseries\classify}\par}{} %%%======================...


9

I'm not sure if this solution applies to your needs, since your examples are not precise enough but the listofitems package seems to do the job: \documentclass{article} \usepackage{listofitems} \begin{document} \readlist\f{foo,bar,baz} Now f[1] is \f[1] and f[3] is \f[3]. \end{document}


6

well you shouldn't use \a that is already defined. But beside from this, naturally commands can do different things depending on the argument. If you know your arguments are numbers, you could e.g. get the content from a sequence: \documentclass{article} \ExplSyntaxOn \seq_new:N\l_rax_data_seq \seq_set_from_clist:Nn \l_rax_data_seq {foo,bar,baz} \...


1

As pointed out by Ulrike Fischer in the comments \def \sb {{\bf s}} overwrite thes LaTeX kernel command \sb (defined as \let\sb=_) with a new definition. Because the code uses \def this happens without warning. (If the code had used the LaTeX convention \newcommand there would have been an error message telling us that \sb is already defined.) Unfortunately,...


3

When \maketitle is typesetting the title, it uses \@title. By default, \@title is defined as: \def\@title{\@latex@error{No \noexpand\title given}\@ehc} so the document: \documentclass{article} \begin{document} \maketitle % <-- error here \end{document} will throw the error in \@title. When you do \title{<anything>}, the \title command does: \gdef\...


0

If you want to get the effect of \begin{addmargin}[2em]{0em} \lol{MY TEXT HERE} \end{addmargin} the simplest way to do this is to modify your existing definition of \lol to include the \begin…\end of the enclosing environment. So you would rewrite your definition¹ as: \NewDocumentCommand{\lol}{m}{ \begin{addmargin}[2em]{0em} \vspace{4pt}\color{...


2

This is a longer comment. As I understand it, the first four arguments of \pgfpicture is one way to hard-code the bounding box of the picture. For example, you specify that the bounding box is from (0, 0) to (50pt, 3cm); but your picture actually extends to (10cm, 2cm). So it exceeds the right margin. If, instead, some line goes to (-5cm, 0), then that line ...


2

This tokcycle based approach is set up to handle tokens (and groups) in the input stream in a successive manor. It can thus be programmed to emulate verbatim in most ways (the exception being that the grouping tokens {} must be balanced) But as we see in the MWE, special characters like {#$%^&\_} are all handled. I have further set up the cycle to ...


3

I cannot recommend using a macro with undelimited-argument-syntax for producing multiline-verbatim-material: The question of handling indentation of the source code will cause confusion because with verbatim-material indentation-spaces in the source-code are tokenizend and therefore show up as horizontal space/visible space in the output. In order to exhibit ...


9

The fancyvrb package allows you to define your own environments. If you use this you can just change the definition: \documentclass[]{article} \usepackage{fancyvrb} \usepackage{fvextra} \DefineVerbatimEnvironment{MyVerbatim}{Verbatim}{breaklines=true,numbers=left,breakafter=\},breakbefore=\\} \begin{document} \begin{MyVerbatim} text text text text text \...


0

Without any modifications, use the optional parameters: \newdualentry [ plural={Light Emitting Diodes}] % Glossary [longplural={Light Emitting Diodes} % Acronym ,shortplural={LEDs}] {led}{LED}{Light Emitting Diode}{...}


1

Probably the following examples gives a clue of TeX's concept of replacing tokens by other tokens in the stage of expansion: Example 1: \documentclass{article} \begin{document} \verb|\newcommand\Command[1]{%|\\ \null\kern\parindent\verb| Command got the following argument: \texttt{\detokenize{#1}}%|\\ \null\kern\parindent\verb|}| \newcommand\Command[1]{% ...


1

Use environment=myframe option: \documentclass{beamer} \newenvironment{myframe}[1]{% \setbeamercolor{background canvas}{bg=yellow} \begin{frame}[environment=myframe,fragile]{#1} }{ \end{frame} } \begin{document} \begin{frame}[fragile] \frametitle{first slide} regular \end{frame} \begin{myframe}{some title} myframe with different bg and maybe also an image ...


1

I just wrote a macro \WrapKArgsBetweenTokens which is driven by \romannumeral-expansion and therefore delivers the result after two expansion-steps. Syntax: \WrapKArgsBetweenTokens{% ⟨TeX-⟨number⟩-quantity of value K⟩ }{% ⟨tokens in case of error, i.e., in case amount of arguments with tokens to prepend =/= ...


4

\ifcsname does not define a csname for undefined names (unlike \csname) so \ifcsname foo\endcsname\else \expandafter\show\lastnamedcs \fi \bye produces > \^^@=undefined. <recently read> \IMPOSSIBLE. l.2 \expandafter\show\lastnamedcs it is generating an internal inaccessible token that isn't usable with \newdimen (or anything). A ...


3

This is far from complete but it does some cases. It is very chatty on the terminal: token is p variable found 68 p token is of stop at of collected: 68 2: eval result is 68 x token is P variable found 80 P token is points, stop at points, collected: 80 2: eval result is 80 x token is p variable found 68 p token is * token is 100 token is / token is P ...


1

\documentclass{article} \usepackage{longtable} \newcommand{\newLine}[2]{% \def\thisName{#1}% \ifx\thisName\lastName\else\textbf{\uppercase{#1}}\fi \gdef\lastName{#1}&% #2 \\} \begin{document} \begin{longtable}{l p{.75\textwidth}} \newLine{Hussein}{Hello.} \newLine{Hussein}{``Hussein'' should not be beside this line.} \newLine{...


1

I'm not quite sure how to answer after the bunch of edits, so I try to go step by step... in order to be concise I assume that all the following snippets start with the code \documentclass[12pt]{article} \usepackage{amsmath} \usepackage{tikz-cd,tikz} \usetikzlibrary{decorations.pathmorphing} The original question \DeclareRobustCommand{\twoheads}{% \...


1

So you wrote: \newcommand{\emailTo}2][][email address]{The #2 that #1 is sent to.} This is very close to what you want, but you managed to get your brackets out of place. You wanted to put the 2 inside the first set of brackets (there's also a random closing bracket hiding in there as well). Except that with \newcommand, the optional argument must be the ...


1

Using old-style \newcommand, this might be an approach. \documentclass[10pt,a4paper]{article} \newcommand{\emailTo}[1]{\def\tmp{#1}\emailToAux} \newcommand\emailToAux[1][email address]{% The #1 that \tmp{} is sent to. } \begin{document} \emailTo{somebody} \emailTo{somebody}[parcel] \end{document}


2

EDIT: I've added a new answer that uses a key=value interface, and allows forwarding values that contain a comma. If this isn't necessary for your use, take a look at the original answer at the bottom. New Answer If you need a key=value interface and want to be able to pass arguments containing commas to the underlying keys, you'll need an up to date LaTeX ...


0

You want \SPACE to be \let to a space token for the \ifx test, and \DOT to be \let to a catcode12 . or \def to expand to a catcode 12 . (I do the latter here) \def\DOT{.} \catcode`\.=\active \lowercase{\let\SPACE= } % \def\dotnext{\ifx\peektoken\SPACE\DOT T\else \DOT F\fi} \def.{\futurelet\peektoken\dotnext} Lorem. Ipsum. is. simply. dummy text. a.b.c. ...


3

You want to expand \thenamecounter before \pdffield_checkbox:n absorbs the argument. \RequirePackage{pdfmanagement-testphase} \DeclareDocumentMetadata{uncompress,pdfversion=2.0} \documentclass[]{article} \usepackage{l3pdffield-testphase} \usepackage{hyperref} \newcounter{namecounter} \ExplSyntaxOn \NewDocumentCommand{\mcheckb}{mm} { \stepcounter{...


9

The LaTeX sectioning commands use the \@afterheading macro, which does three things: it says \@nobreaktrue, which is defined as \global\let\if@nobreak\iftrue and is used in many places of the LaTeX kernel to prevent a page break: in \@esphack which is used at the end of \label, \index, \vspace and other places; in \protected@write which is used in most file-...


0

This behaviour is the result of a ID-10t error. As @Black Mild pointed out in a comment on their answer, I passed \newcommand[3]{\myDiagram} instead of \newcommand{\myDiagram}[3].


2

I suggest the following way: \documentclass[tikz]{standalone} \begin{document} \newcommand*{\myDiagram}[3]{% \path (-90:1) node (1) {$1$} (30:1) node (2) {$2$} (150:1) node (3) {$3$} ; \draw[nodes={red,midway,scale=.6}] (1) --(2) node[below right] {#1} --(3) node[above] {#2} --(1) node[below left] {#3} ; }% \begin{tikzpicture} \myDiagram{$1$}{$3$}{$2$} ...


0

The root cause seemed to be missing makeatletter and makeatother. \makeatletter \newcommand\stars{\@startsection {stars}{1}{\z@}% {-3.5ex \@plus -1ex \@minus -.2ex}% {2.3ex \@plus.2ex}% {\normalfont\Large\bfseries}} \makeatother


2

You want to use an expandable mapping, so \seq_map_function:NN. \documentclass{article} %\usepackage{xparse} % not needed with LaTeX 2020-10-01 or later \usepackage{tabularray} \ExplSyntaxOn \seq_new:N \pb_mytblr_entries_seq \NewDocumentCommand { \entry } { m m m } { \seq_put_right:Nn \pb_mytblr_entries_seq { { #1 } { #2 } { #3 } } } \cs_new:Nn \...


2

[In your examples you did not obey all expl3-conventions for naming control sequences. In my coding-examples I renamed things to fit the conventions.] In your example the \entry-macro is used for accumulating things within a sequence-variable. You use it within the mytblr-environment. At the end of that environment the things stored in the variable are to be ...


2

As Steven B. Segletes already said: The tblr-environment wants to "see" \MyTable expanded. You can achieve this as shown by Steven B. Segletes via temporary macros. Another approach is having two macro-arguments and expanding the first macro-argument before exchanging it with the second one: \begin{filecontents*}{mytable.tex} 1 & 2 \\ ...


Top 50 recent answers are included