Tag Info

New answers tagged

2

If amsmath is used then \iftagsleft@ is true or not. For article and other classes, you need to check the definition of \@eqnnum or you could use \@ifl@aded{clo}{leqno}{yes}{no}


6

You can use \renewcommand*\div{\mathbin{\mskip1mu\nonscript\mskip-1mu% ∕% \mskip1mu\nonscript\mskip-1mu}} or some value other than 1mu the skip is always added but in non-script (ie text and display) styles add the negative amount to cancel it out.


1

Not good, but not too bad: %begin time definitions \newcount\eyear \newcount\emonth \newcount\eday \newcount\ehour \newcount\eminutes % \time \newcount\hour \newcount\hours \newcount\minutes \hour=\time \divide\hour by 60 \minutes=\time \hours=\hour \multiply\hours by 60 \advance \minutes by -\hours \def\fromdate[#1-#2-#3 #4:#5]{% \eyear=\year% ...


5

Here's a LuaLaTeX-based solution. It uses Lua's powerful string.gsub function in the definition of the \replace macro. The macro \replace can be used recursively. % !TEX TS-program = lualatex \documentclass{article} \usepackage{luacode} % for luacode environment and \luastring macro %% Lua-side code \begin{luacode} function myreplace(s,a,b) x = ...


8

As written, the posted code produces ! Undefined control sequence. l.22 \elapsedmonthsyears so changing the last two calls to use \elapsedyearsmonths produces ! Use of \elapsedyearsmonths doesn't match its definition. l.22 \elapsedyearsmonths{ as the call on line 22 is followed by a { (the end of line in the error message shows TeX stopped at that ...


7

A complex solution that only replaces complete words: \documentclass{article} \usepackage{xparse,l3regex} \ExplSyntaxOn \NewDocumentCommand{\replace}{mmm} { \marian_replace:nnn {#1} {#2} {#3} } \tl_new:N \l_marian_input_text_tl \tl_new:N \l_marian_search_tl \tl_new:N \l_marian_replace_tl \cs_new_protected:Npn \marian_replace:nnn #1 #2 #3 { ...


8

This uses the higher-level macro StrSubstitute from xstring package. Use [0] as first optional parameter to replace all occurences of here, but as egreg stated in a comment, it will also replace in words like where or there \documentclass{article} \usepackage{xstring} \begin{document} \StrSubstitute[0]{Text should be replaced here, here and ...


11

\def\replace#1#2#3{% \def\tmp##1#2{##1#3\tmp}% \tmp#1\stopreplace#2\stopreplace} \def\stopreplace#1\stopreplace{} \replace{Text should be replaced here, here and here}{here}{Latex} \bye written as plain tex but would work in latex too.


1

You have to expand the \the\ga argument. For example: ... \newcommand{\btreematrixnode}[3]{% % #1 ... the level of the node % #2 ... number of node of level #1 % #3 ... values as comma separated list \ga = 1% \let\mymatrixnodecontent\empty \foreach \x in #3 {% \edef\tmp{{\x}{\the\ga}}% ...


2

If you desire to align the text into two side-by-side sections you can use minipages: Notes: For the minipage on the right you had used an itemize which adds bullets for the list items, but as you show numbers in your image, I changed that to enumerate. Code: \documentclass[11pt,twoside,openany,svgnames,x11names]{book} \usepackage{wallpaper} ...


2

As mentioned in the comments, you have two simple options that I present below. However, I'm not quite sure what you are after. \documentclass{minimal} \usepackage{forest} \forestset{ with translation/.style={ l sep=0,inner xsep=0, append translation/.expanded/.wrap pgfmath arg={\gettranslation{##1}}{content}, content/.expanded/.wrap ...


2

This is not breakable and uses tcolorbox: \documentclass{article} \usepackage[many]{tcolorbox} \usepackage{lipsum} \definecolor{keyideascolor}{rgb}{0,0.5,0.1} \makeatletter \newtcolorbox{keyidea}[1][]{ enhanced jigsaw, left=7pt,right=7pt,top=1.75ex,bottom=1.25ex, boxrule=0pt, arc=0pt, before=\par\noindent\vspace{2em}, ...


5

An explicit number can be expanded without changing it and the unwanted command sequence can be redefined to vanish itself, when expanded: % Setup \makeatletter \newif\ifintheway \def\@citeb{foobar} \def\bfoobar{\inthewayfalse 17} % Extract the number from \csname b\@citeb\endcsname % and store it in the macro \mynumber \begingroup ...


0

Thanks to @egreg's answer, I finally got to an example which demonstrates how to patch and \show a \newcommand, which otherwise has some protection (see Are commands defined by \newcommand[.][.]{.} robust?). The problem is, when you \show a \newcommand, you just get something like "\@protected@testopt \mycmd \\mycmd {}.", not the "real" internals of the ...


5

\documentclass[11pt,spanish,a4paper]{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} OK so far except that theses usually have chapters so book or report might be preferable. \setlength{\parskip}{2ex} \setlength{\parindent}{0pt} Better to use parskip: \usepackage{parskip}% but do you really want no indentation in a thesis? ...


4

\# \$ \% \& \~ \_ \^ \{ \} are very different types of commands, \% makes a percent but \^ does not make ^ it is a command that takes an argument \^{a} constructing accented letters. You can use \detokenize{@Model.ReportTitle} then you basically only need to quote \( \} and \% to ensure that the construct has balanced braces. and add ...


2

You can use the \vspace*{length} command to write to the same line multiple times. Combine this with the \baselineskip length to jump several lines up or down. Additionally, change \baselineskip locally to make room for sub-line legends: \documentclass{article} \pagestyle{empty} \parindent0pt \begin{document} \bgroup % Double line space (or use setspace ...


3

Although in older posts of mine, I was reluctant to recommend the use of LuaLaTeX, the code has now matured enough and the LuaTeX Team is doing such a great job, that I would heartily recommend that any "thesis class" seriously considers using LuaLaTeX. Thesis templates are about enforcing styles and parsing is one of the stengths of Lua. As you wish to ...


4

The implementation is not the best, but just to see it can be done: \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\macroa}{ >{\SplitArgument{1}{,}}m } {% \processtwo#1% } \NewDocumentCommand{\processtwo}{ m m } {% \IfNoValueTF{#2} {% \semicolonfalse #1, % } {% \semicolontrue #1 \textbf{\textit{#2}}% ...


2

What you think works doesn't do it. By chance you have selected two words without depth, while # has it. Try with: \documentclass{article} \usepackage{tikz} \newcommand{\mkTikzCoord}[2]{% \tikz[remember picture, baseline=(#1.base)]{\node [inner sep=0, outer sep=0, text depth=.25ex, text height=1.5ex] (#1) {#2};}% } \begin{document} Some text where I ...


3

You are confusing latex with the square backets for the optional arguments. When latex sees \TestA[\TestB[111]] it thinks that the optional argument for \TestA is \TestB[111. Now it tries to evaluate this expression and gets confused because \TestB is not conforming to syntax. To fix this you need to put brackets around the optional argument to \TestA: ...


1

You can use \edef\sum in this way: \edef\sum{\mathchar\the\sum\limits} ... A summation $\sum_{i=1}^{n} a_{n}$ ...


0

As \int is defined \intop\nolimits, you have at least two natural ways of obtaining limits placed where you want: \documentclass{article} \begin{document} \[ \int_{0}^{1}1\,dx \] \def\Int{\int\limits} \[ \Int_{0}^{1}1\,dx \] \let\uglyamericanint\int \def\int{\intop\limits} \[ \int_{0}^{1}1\,dx \] \end{document} (I have no tools to crop the ...


3

This is as easy as \documentclass{article} \usepackage{amsmath} \makeatletter \renewcommand{\slimits@}{\limits} \renewcommand{\ilimits@}{\limits} \makeatother \begin{document} A summation $\sum_{i=1}^{n} a_{n}$ and an integral \[ \int_{0}^{1} x^2\,dx \] also inline: $\int_{0}^{1} x^2\,dx$ \end{document} However the result is typographically terrible. ...


0

When you \def\sum{\sum\limits}, you tell TeX that \sum expands to the two tokens \sum and \limits. This \sum then expands to \sum\limits, expanding to \sum\sum\limits, expanding to \sum\sum\sum\limits, ad nauseam. Using the different name will resolve the issue, but I encourage you to not do this. There are many instances where such a shortcut will break ...


3

To collect your label in the "Tree" interface, follow these steps: Show the "Options Interface" (Options -> Options Interface) Double-click the "Tree" item (Tree.ini gets opened) Locate the lines BRANCH="Labels-TeX" BRANCH_CAPTION="Labels (#)" // Change Mode from TeX to ? to disable this item BRANCH_MODE_FILTER="TeX|DTX;INS;STY;AUX" ...


0

What you want is a macro. Wikibooks has excellent tutorial on the topic. As for the code environment, use the listings package: Wikibooks, CTAN. Here is a quick example of what you can do. The \newcommands there make three, well, new commands: \compbox, \compline, and \comp. \documentclass[a4paper]{article} \usepackage{fancybox} \usepackage{listings} ...


3

Parameters can be used only in the scope of a macro definition, so your ##2 in the file is meaningless. \begin{filecontents}{test-disputeUS} \section{Governing law. Arbitration} \label{sec:dispute} The parties agree that the Agreement shall be governed by the laws of the State of \ifstr{\control}{DE}{Delaware}{New York}, USA, without giving effect to its ...


3

You have to use suffix and not expr: def anchors(suffix p) = pair p.n, p.e, p.s, p.w; p.n := .5(ulcorner p + urcorner p); p.e := .5(urcorner p + lrcorner p); p.s := .5(llcorner p + lrcorner p); p.w := .5(ulcorner p + llcorner p); enddef; path b; b := unitsquare scaled 1pt; anchors(b); show b.n; show b.e; show b.s; show b.w; end This outputs ...


3

Behold my psychic power! Use \cslet to set \answer1 etc. to the current definition of \answer, not answer itself. \documentclass{article} \usepackage{etoolbox} \newcounter{a} \setcounter{a}{0} \newcommand\setans[2]{% \csdef{answer#1}{#2}} \newcommand\addans[1]{% \stepcounter{a}% \cslet{answer\thea}{#1}} % <--- Not \csdef! ...


5

A macro that supports complex ranges must use the full force of expl3. Here's a possible solution: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\range}{ m m } { \cashner_range:nn { #1 } { #2 } } \tl_new:N \l__cashner_range_input_tl \seq_new:N \l__cashner_range_input_seq \bool_new:N \l__cashner_range_multi_bool ...


1

Have you tried the ifmtarg package? It provides the macro \@ifmtarg{<arg>}{<Code for arg empty>} {<Code for arg not empty>} Use texdoc ifmtarg for the documentation.


6

It's quite easy with xparse: \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\range}{ m >{\SplitArgument{1}{ }}m } {% \dorange{#1}#2% } \NewDocumentCommand{\dorange}{ m m m } {% \IfNoValueTF{#3}{#1~#2}{#1[]~#2--#3}% } \NewDocumentCommand{\defineabbreviation}{ m m m } {% \NewDocumentCommand{#1}{o}{\IfNoValueTF{##1}{#2}{#3}}% ...


4

The code inside siunitx (v2) uses a loop over each token in the input before comparing this to the various lists of possible 'number parts'. As that process cannot make assumptions about the nature of the tokens and as it covers a variety of input forms, it's rather complex. I'm currently re-writing it all to be more efficient and clear but the need to work ...


5

You can use a \romannumeral trick: \if\relax\detokenize\expandafter{\romannumeral-`\Q#1}\relax The missing space after `\Q will trigger expansion of #1 (after macro substitution, of course). Since this expansion ends at the first unexpandable token, this should be what you want. However a leading space will be ignored. \def\notempty{\relax} ...


6

\documentclass{article} \usepackage[T1]{fontenc} \def\foo#1{\par \texttt{<\detokenize{#1}>} \expandafter\if\relax\detokenize\expandafter{\romannumeral0#1}\relax \if X#1X% empty\else not empty\fi \else not empty\fi} \begin{document} \foo{} \foo{ } \foo{\empty} \foo{{}} \foo{\sqrt} \foo{\csname @gobble\endcsname{hello}} \end{document}


1

The two-line solution which uses only TeX primitives follows: \def\sdef#1{\expandafter\def\csname#1\endcsname} \def\mkMac#1{\sdef{the#1}{The macro #1}\sdef{#1}##1{\sdef{the#1}{##1}}} \mkMac{affilation} \affilation{University} Welcome to \theaffilation


1

You can define a new template based on the frame number one for footline: \documentclass[compress,final]{beamer} \usepackage{ragged2e} % for justifying \usepackage{lipsum} % for random texts \usepackage{geometry} \geometry{lmargin=.5cm, rmargin=.5cm} ...


7

They mean something like \documentclass[graybox,envcountchap,sectrefs]{svmono} but with smallextended in the options between [] and perhaps a different class than svmono depending on your requirements. Springer have extensive documentation and examples in a zip file you can download from ...


0

LaTeX defines a short interface similar to that provided by etoolbox in the form of \@namedef (from latex.ltx): \def\@namedef#1{\expandafter\def\csname #1\endcsname} Here is a minimal example showing the usage: \documentclass{article} \makeatletter \newcommand*{\mkMac}[1]{% \@namedef{the#1}{The macro #1}% \@namedef{#1}##1{\@namedef{the#1}{##1}}} ...


1

The best way to define new macros is to use the etoolboxs \csdef: Notes: Note that \aa is already defined., so you should use an alternate name. As \csdef won't issue an error in that case, I have added a test to make sure that the code issues an error if you attempt to redefine an existing macro. You can also use \csname...\endcsname to build names of ...


5

There are a few errors in the definition of \remainder and \othermacro: a \newcount declaration mustn't go inside them, because this would waste a counter at each call. Also a space after #2 is significant and it means that TeX looks for a space after the second argument, raising an error if it doesn't find one and taking as second argument everything that ...


8

The requirement is easy to fulfill: \documentclass{article} \usepackage[nopar]{lipsum} % just for the example \newcommand{\verset}[1][]{\stepcounter{verset}% \textbf{\theverset. \if\relax\detokenize{#1}\relax \else #1 \fi }% } \newcounter{verset} \begin{document} \lipsum[1] \verset \lipsum[2] \verset[Description] \lipsum[3] ...


9

Using Styles (Recommend Approach): You should use tikzset to define your own styles. Below, I defined My Axis Style for your axis style, and My Plot Style for your plot: Notes: Removing the blank line between the two sub figures will put the figures next to each other. This is the similar to the behavior in normal text paragraphs where a blank line ...


3

Run with pdflatex --shell-escape ... \documentclass{article} \usepackage[crop=off]{auto-pst-pdf} \usepackage{pst-barcode} \begin{document} \pspicture(1in,1in)\psbarcode{\jobname}{}{qrcode}\endpspicture \qquad \pspicture(0.5in,0.5in)\psbarcode{\jobname}{format=micro}{qrcode} \endpspicture \end{document}


8

The macro \getfromjobname is not “fully expandable”, due to usage of \ifthen, so it can't be used in the argument to \qrcode. Using directly \gettwofromjobname works. If I name the file kinda-hanta.tex and modify it to be \documentclass{article} \usepackage{qrcode} \usepackage{varsfromjobname} \begin{document} \def\foo{hanta}% ...


7

macro names do not need to be allocated, you can have (up to implementation defined limits) arbitrarily many csnames with macro definitions. But classic TeX only has 256 registers of each type (extended to 32768 in etex) so length (skip) registers need to be allocated from a fixed pool with separate commands for allocating a register (which just reserves the ...


1

\newlength is defined as a \skip, i.e. register provided also to calculations (\newlength reserves a new skip, \setlength sets its value), while \newcommand in this case would be only a string.


5

Please always post complete documents, as below, not just fragments. If I start with \documentclass{report} \begin{document} \newcommand{\met}{\cancel{\it{E}}_{T}} \chapter{\met} \end{document} I get ! Undefined control sequence. \met ->\cancel so change to \documentclass{report} \usepackage{cancel} \begin{document} ...


1

\newcommand{\stringnumber}[2]{% \ifnum #2>0 #1% \stringnumber{#1}{\numexpr#2-1} \fi } The previous code, when the number of requested repetitions is high, generates very long token lists. Here's a better implementation that avoids the problem. \documentclass{article} % it's better if the number of repetitions is first ...



Top 50 recent answers are included