New answers tagged

1

Most latex commands are not safe in \xdef (which is why latex has a \protect mechanism and \protected@edef) but here you just want \let I think and don't need to expand \BODY at all. \documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[german]{babel} \usepackage{environ} \usepackage{etoolbox} %%Environments %Liederbuchumgebung ...


1

The glossaries package has been changed since this question and the other answer were posted. If you are still encountering this problem, update your version of glossaries. Note that \newglossaryentry is still a “short” command, so you can't have paragraph breaks (except through \glspar). \longnewglossaryentry allows explicit paragraph breaks. It's best to ...


4

Define \UnitLabel with an argument: \documentclass{article} \usepackage{lipsum} \usepackage{xparse} \newcounter{Unit} \NewDocumentCommand{\UnitLabel}{m}{% \makebox[4.5em][l]{Unit #1}% } \NewDocumentCommand{\Unit}{ m }{% \refstepcounter{Unit}% \section*{\UnitLabel{\Roman{Unit}}#1} \addcontentsline{toc}{section}{\UnitLabel{\Roman{Unit}}#1}% } ...


3

Like this? \documentclass{article} \usepackage{xcolor} \newcommand{\sectioncolored}[3]{% \section{\textcolor{#1}{#2} #3}% } \makeatletter \def\entrylistsplitfirst#1 #2\@nil{#1} \def\entrylistsplitsecond#1 #2\@nil{#2} \newenvironment{entrylist}[2]{% \edef\tempa{\expandafter\expandafter\expandafter\entrylistsplitfirst #2\@nil}% ...


3

Use \DeclareExpandableDocumentCommand -- this does not allow an optional argument at the end of the argument list, but this is no issue here! The \NewDocumentCommand version isn't expandable, see e.g. \show\UnitLabel: \UnitLabel=\protected macro: ->\makebox [4.5em][l]{Unit \Roman {Unit}}. l.25 \show\UnitLabel i.e. \UnitLabel is protected. The xparse ...


1

\apptocmd doesn't like to be in the argument to another command when # is involved. You can do it with a conditional: \documentclass{article} \usepackage{etoolbox} \newcommand\app[1]{\textbf{#1}} \newif\ifdebugmode \debugmodetrue % comment for not applying the patches \ifdebugmode \newwrite\appfile ...


2

I am unclear on the detailed behavior desired, but... Is this what is desired? \documentclass{article} \usepackage{xpatch} \newcommand\app[1]{\textbf{#1}} % <- #1 is appended's macro's parameter \def\addtoapp#1{% \apptocmd{\app}{#1}{}{} % <- passing appended macro's parameter to appended macro again } \begin{document} \app{Food App} \addtoapp{This ...


0

Another answer from the perspective of "you don't need variable variables". This uses \long\def and adds a \vtop box to the material under the line. \documentclass{article} \usepackage{setspace} \long\def\sigblockB#1#2#3% Defined 3 arguments% `\long\def` allows for paragraphs % within the arguments of a control sequence ...


5

If I understand correctly, you want to use the relative positions of the saved nodes in your new picture. That is, each node should refer to a position in the new picture relative to the new origin. Here's some code that saves all the data for a list of specified nodes which can then be restored at a later time in the document. It uses LaTeX3 stuff ...


0

An experimental implementation of hz for plain TeX is available at http://ctan.org/tex-archive/systems/tex-extensions/clasen.


5

The OP's first example is \documentclass{article} \newcommand{\new}{} \begin{document} \new{Why is this printed?} \end{document} and he/she wonders why "Why is this printed?" get printed out. The key to understand here is that something following a macro name, even if it looks like an argument, such as \new{Why is this printed?}, is only an actual ...


0

Download csv2latex and unzip it. Locate two files under source called csv2latex.scpt and csv2latex.scpt. Move them to /usr/local/bin. That is, $ cd to/directory/of/source $ mv csv2latex /usr/local/bin $ mv csv2latex.scpt /usr/local/bin in a terminal window.


2

Add it to the node options, so that it affects the whole node, and not just a part of it: font=\Large Also, the shape is a rectangle by default, and draw uses black by default. So in the end you can just write: \newcommand{\orgnode}[2]{\node[draw, font=\Large, align=center] at (#2) {#1};}


1

By using, as the OP did, \csname \foo@#1\endcsname, a macro is invoked with the name formed by substituting the definition of \foo followed by argument 1, #1. But what the OP's main code suggests isn't that the value of \foo is desired, but rather the letters "foo" themselves, so that the macro being invoked has the "name" of "foo#1", where #1's value is ...


3

the requested syntax seems very odd, but width= and scale= are just variants of scaling with width implying scaling the natural width so you just need the following which avoids duplicating \includegraphics: \documentclass{article} \usepackage{graphicx} \makeatletter \newcommand\zz[1]{#1\ifdim#1pt<1pt \Gin@nat@width\else\textwidth\fi} \makeatother ...


3

It makes very little sense requiring something like width=1.2\textwidth: if the first item is bigger than 1, the image would be scaled to be wider than the text width. And mixing scale and width is rather dubious. However, the customer's always right. ;-) \documentclass{article} \usepackage{graphicx,xparse} \NewDocumentCommand{\mycmd}{o ...


0

Here's a possibility: \documentclass{article} \usepackage{etoolbox} \newenvironment{myenv} {\global\uniqueenvfalse \BeforeBeginEnvironment{unique-env}{\ifuniqueenv\errmessage{ONLY ONE}\fi} something at startup\par} {\par something at end} \newenvironment{unique-env} {\par\global\uniqueenvtrue} {\par} \newif\ifuniqueenv \begin{document} ...


2

It's possible to use a new counter that is checked at the start-up code of the environment. If the counter is equal to zero, all is fine, increase the counter to indicate that is zero not any longer, if the counter is not zero right from the start (because it has been increased already) issue an error message. At the end of the environment the counter is ...


3

You are really trying to make your questions difficult to read. Why are you adding all these unnecessary details? If you want to test if an graphics exists you can try this: (from Check for a valid file before using \includegraphics) \documentclass[]{article} \usepackage{graphicx,todonotes} \makeatletter \newif\ifgraphicexist \catcode`\*=11 ...


2

This will not typeset the file name correctly if the file is missing, but it will find and use the image if present and will typeset something similar to the file name otherwise. \documentclass{article} \usepackage{todonotes} \usepackage{graphicx} \usepackage{xparse} \usepackage{caption} ...


0

Tests using \if..\else..\fi can be outmaneuvred by using arguments that contain unbalanced \if.. or \or or \else or \fi. The following test works without additional packages only by means of expansion without any \if-conditionals. Everything is done by means of delimited macro arguments. Of course you cannot successfully apply test-macros on arguments that ...


7

Try using \let instead of \renewcommand: \documentclass{article} % \newcommand{\signS}{$+$}% \newcommand{\signT}{$-$}% \newcommand{\signU}{}% % \begin{document} old \textbackslash signS: \signS \let\signU\signS \let\signS\signT \let\signT\signU new \textbackslash signS: \signS \end{document}


9

The easiest way is probably to replace \renewcommand{\signU}{\signS} by \let\signU\signS, etc. Then \signU is assigned the current meaning of \signS. Your method does not work because \renewcommand does not expand the definition text at the time of definition. Instead, it is expanded when the command is used.


16

Here is an \ifnum comparison that can handle non-numeric inputs. It does it by comparing 1 with 0#1. If #1 is a number, the \ifnum comparison works in the standard way, since the leading 0 does not affect the numerical value. If #1 is not a number, then the \ifnum argument expansion stops after the 0 with a false comparison (having already printed out ...


8

\pdfstrcmp of pdfTeX expands two token groups and compares them as strings. If they are equal, \pdfstrcmp expands to 0, which can be tested with \ifnum or \if: \ifnum\pdfstrcmp{#1}{1}=0 % space ends the number zero here ... \else ... \fi or \if0\pdfstrcmp{#1}{1}% ... \else ... \fi Package pdftexcmds' \pdf@strcmp hides the different names and ...


2

\hss "horizontal shrink/stretch" will shrink to negative sizes if needed or stretch as much as needed, as requested in comments. \documentclass{article} \begin{document} \begin{flushleft} \makebox[\textwidth][s]{%%%% \parbox{0.5\textwidth}{some Text}%%%% \hss \parbox{0.5\textwidth}{some Text}%%%% \hss \parbox{0.5\textwidth}{some Text}%%%% } ...


2

Here I introduce \Hfill which has a minimum spacing of \Hfillkern (EDITED per OP's comment), but otherwise it is an \hfill. It is defined as \def\Hfill{\hspace{\Hfillkern}\hfill} The user may specify the \Hfillkern length via \setHfillkern{}. Here is the MWE, with \Hfillkern set to -.25\textwidth. \documentclass{article} \parskip 1em \parindent 0pt ...


1

Another option, and for me a simpler one (but perhaps not for your real application), is to use TeX primitives: \documentclass{article} \newif\ifWorkshop\Workshoptrue% set workshop to be true \newif\ifTraining\Trainingfalse% set training to be false \begin{document} \ifWorkshop% \ifTraining Workshop and training!\else Workshop and no training!\fi% ...


3

You are using \ifboolexpr in the wrong way. In your case you need to use the test operator: \documentclass{article} \usepackage{etoolbox} \begin{document} \ifboolexpr { test {\ifundef{\dockerWorkshop}} and test {\ifundef{\training}} } {both undefined} {at least one defined} \end{document}


2

The answer is no. I made a command that does it for me: \newcommand{\newmanalkene}[6][0]{ \def \alkeneangle {-#1} \pgfmathsetmacro{\Cdist}{.3*cos(#1*3)^2} % rear atom position \def \bondlengthfront {1.25} % front atom's bond length \def \bondlengthback {.95} % back atom's bond length ...


5

There is no concept of best in the TeX world. As mentioned in the comments, most active key-value handling packages are pgfkeys and the l3keys. The latter is also inspired by pgfkeys however it requires a minimum level of LaTeX3 knowledge which might be a bit baffling for newcomers since it doesn't have a comprehensive introduction and manual (yet!). ...


0

Here is an answer which depends heavily on the work done in User Mico's answer, but instead; whenever a \hyperlink (linking to a certain \hypertarget) is inserted, the title of that target (the second argument of \hypertarget) is automatically used as a second argument for that \hyperlink, by adding the following excerpt of code: \makeatletter ...


1

Don't do it, unless there is a special reason to. Underscores have special meaning (category code 8), to denote a subscript in math mode. Only catcode 11 (alphabetic) characters can be invoked in a macro name as \macroname. Other approaches could be used to place an underscore in a macro name as shown below, but gyrations are required to invoke the macro ...


2

You can use readfrom: string rf; def init = forever: rf:=readfrom "var.mp"; exitif rf=EOF; scantokens(rf); endfor closefrom "var.mp"; draw (0,A)--(10,B)--(20,C); enddef; beginfig(1); init; endfig; end.


1

Here's a solution that makes use of the \hypertarget/\hyperlink machinery of the hyperref package to create cross-referencing links. The \hypertarget macro places the "anchor", and the \hyperlink macro generates a call-out (in the form of a hyperlink) to the anchor generated by \hypertarget. Both macros take two arguments: the first is the "anchor text" ...


1

Though there are already good answers, I contribute the version, I used for my currently growing Liederbuch-package: \def\TesT#1{ \expandafter\def\csname test\Alph{#1}\endcsname{} } \newcounter{wseva} \setcounter{wseva}{4} \TesT{wseva} \def\doesItExist#1{ \expandafter\ifx\csname test\Alph{#1}\endcsname\relax no \else yes \fi } \begin{document} ...


2

There are a few problems with your code. The code \ifdefined\expandafter\AuthorName\Alph{loopTitleCoverAuthor} tests whether \expandafter is defined. However the code \expandafter\ifdefined\expandafter\AuthorName\Alph{loopTitleCoverAuthor} would do no good either, because you'd get, when loopTitleCoverAuthor has the value 1, \ifdefined\AuthorName A ...


4

The test \value{A} < \value{B} works for me. I've used \@ifundefined{csname}{true}{false} where csname is the command name to be tested without the escape character \. The most important thing here is constructing the various command names, with \csname foo\Alph{...}\endcsname. \documentclass{article} \usepackage{forloop} ...


0

Use \DeclareMathOperator{\dom}{dom}.


3

Let's look at the basics. First of all, \textwidth, \textheight and \linewidth are <dimen> registers, internally defined with \newdimen. If you do \def\textwidth{\linewidth} you are not setting \textwidth to the current line width, but just making \textwidth into a macro that will expand to \linewidth (the name of the internal register that stores the ...


1

If you don't want to use color package and you want to start automatic coloring then you can use pdfcsplain format with OPmac and no LaTeX: \input opmac \localcolor \def\registerword#1{\sdef{w:#1}{{\Red#1}}% \expandafter\mubyte\csname w:#1\endcsname \space#1\endmubyte} \mubytein=0 \registerword { is } \registerword {paragraph} \registerword {text} ...


1

When I want part of my text be displayed in red, I usually put this macro in the preamble: \newcommand{\red}[1]{\textcolor{red}{#1}} and in the text I use: Some normal (black) text \red{the part of the text that I want to be red} some other text.


2

If ( is used, it will be absorbed as #2. \documentclass{article} \usepackage{tikz} \makeatletter \def\macro{\pgfutil@ifnextchar[{\macrob}{\macrob[]}} \def\macrob[#1]#2{% \begingroup \def\parenthesis@for@err{(}% \def\maybe@parenthesis{#2}% \ifx\maybe@parenthesis\parenthesis@for@err \PackageError{mynicepackage}{You donkey!}{I told you to use {}, ...


2

Perhaps not the easiest or quickest way, but the \@ifnextchar way could be exploited to test whether there's a ( after the optional argument [] (it does not check for ) however. Use \GenericInfo{...}{...} to write some information to the Log File \documentclass{article} \usepackage{tikz} \begin{document} \makeatletter ...


2

Though I recommend to use the answer from @egreg here is a way to implement what you are looking for using \@ifnextchar. The idea is that \sigblock prepares everything until it comes to processing the lines beneath the signature field. Then \sigblock@ is invoked which will set the next grouped argument as a line beneath the signature field and starts a ...


1

Ok, so I found a temporary solution. By deactivating the option "load included files automatically" (just translated from German to English, no guarantee it's exactly named like this) in the editor's tab of TeXstudio's options the freezing behaviour is gone. But of course I'll have to find all the references, citations etc. manually now. Not much better ...


5

I have no idea whether this answers your question or why you would be disappointed if you could not use .bib files to exploit something. Nor do I understand why Turing completeness is supposed to be a requirement for capacity to be exploited or what your concept of a Turing complete device is. However, if you wish to know whether you can define a macro in ...


2

By trying to solve this problem I've come up with a possibly interesting macro, so I want to share it here. This macro is called \vardef and allows us to define a macro which can receive a variable number of arguments (any number, not limited to 9 arguments) enclosed in curly brackets. Inside the definition of a \vardefined macro one can use the macro ...


7

You're overthinking: the tool is already there, namely tabular. \documentclass{article} \newcommand{\sigblock}[3]{% \par\vspace{\medskipamount}\noindent \hspace*{#1in}\makebox[#2in]{\hrulefill}\\*[.2ex] \hspace*{#1in}% \begin{tabular}{@{}l@{}} #3 \end{tabular}% } \begin{document} \sigblock{0}{3}{Notary Public \\ At Large} ...


1

Use a \Longstack. \documentclass{article} \documentclass{article} \usepackage{stackengine,lipsum,setspace} \setstackEOL{\cr} \def\sigblock#1#2#3% Defined 3 arguments% {\singlespacing{\vbox{\vskip.75in\noindent\hskip#1in% {\hbox to #2in{\leaders\hbox to 0.00625in{\hfil.\hfil}\hfill}}}% \par\noindent\hskip#1in\Longstack[l]{#3}}} \parindent 0pt ...



Top 50 recent answers are included