Hot answers tagged

10

The name of the internal counter is \c@testB. And \value will work if you remove the backslash. \documentclass[12pt,a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[german]{babel} \begin{document} \newcount\testA \testA=1 \newcounter{testB} \setcounter{testB}{1} \makeatletter \ifnum\testA=\c@testB TRUE \else FALSE \fi \makeatother ...


8

The solution is to use \ifnum\testA=\value{testB}


5

A quick solution with \int_from_alph:n or \int_from_roman:n from expl3. Note that a and A does not matter here, as well as uppercase and lowercase roman figures are identical here. The \setcounter{section}{\alphtonumber{w}} example was used to show that the macros are expandable. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn ...


5

The backtick in numerical context can be used to get the character code of a letter. This can be used to calculate the position of the letter in the alphabet. The definition range for the argument of \inversalph is a to z and A to Z for \inverseAlph. The letter can be hidden inside a macro (or even nested macros). \documentclass{article} ...


5

If you add \show\bar after doing the \edef, you're informed that > \bar=macro: ->E\global \advance \c@testcount 1\relax E. No assignment is performed inside \edef, only macro expansion. We also have % latex.ltx, line 2099: \def\addtocounter#1#2{% \@ifundefined{c@#1}% {\@nocounterr{#1}}% {\global\advance\csname c@#1\endcsname #2\relax}} ...


4

This answer is based on this comment. \bar can be defined in two steps. First the current value of the counter is used and the expanded form saved in \barI. Then the counter is increased, because the assignment does not work in expandable contexts like \edef. The increased counter value is saved in \barII. Finally macro \bar is composed from \barI and ...


4

\ifthenelse is not expandable and can therefore not be used inside the arguments of \setcounter. However, the TeX primitive \ifnum is expandable: \setcounter{TestCounter}{% \ifnum 5>6 % space ends number 6 7% \else 2% \fi } \arabic should not be used in numeric contexts, because it could contain formatting stuff like font settings. The ...


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

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 ...


3

Do you mean this? \documentclass[10pt,a4paper]{book} \usepackage[latin1]{inputenc} \usepackage{amsmath} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{graphicx} \usepackage{tikz} \usepackage{tocloft} \newcounter{countera} \newcounter{counterb} \newcommand{\toC}[1]{% \stepcounter{% counter#1% } } \begin{document} \toC{a} \toC{b} ...


2

You could load the alphalph package. Then, \alphalph{\value{section}} generates a lowercase-latin "numeral" to represent the value of the counter named section. A full MWE: \documentclass{standalone} \usepackage{polyglossia} \setdefaultlanguage{hebrew} \newfontfamily\hebrewfont[Scale=MatchLowercase]{Ezra SIL} \usepackage{alphalph} \begin{document} ...


2

I don't understand the question, so don't expect this to answer it. But in any case, if you substitute this \expandafter\def\csname clettered#2\endcsname ##1{\expandafter\expandafter\expandafter\csname @clettered#2\endcsname\csname c@##1\endcsname}% \expandafter\def\csname @clettered#2\endcsname ##1{\@arabic##1}% \AddEnumerateCounter*{\expandafter\csname ...


2

A simple wrapper may work here (at least for this simple example) \documentclass{article} %\usepackage{xifthen} \newcommand{\ifelse}[3]{% \ifnum#1 #2% \else #3% \fi } \begin{document} \newcounter{TestCounter} \setcounter{TestCounter}{\ifelse{5 > 6}{7}{2}} \theTestCounter \setcounter{TestCounter}{\ifelse{6 > 5}{7}{2}} ...


2

For counting of money you can use normal TeX counter. This counter stores values in pennies. \newcount\tmpvar \newcount\myvar \def\addvar#1#2 {\let\tmp=#1\addvarA #2.\end} \def\addvarA#1.#2\end{\advance\tmp by #100 \ifx;#2;\else\ifx.#2\else\addvarB#1.#2\fi\fi} \def\addvarB#1.#2#3.{\advance\tmp by \ifnum#1<0-\fi #2#3\ifx;#3;0\fi\space} ...


2

The number is always stored in the counter while \alph and the like are only for displaying the value. For example if you define \newcounter{foo} \renewcommand{\thefoo}{\alph{foo}} with \thefoo you get a, b, c, … but with \value{foo} you can always access the integer value of the counter.


2

paracol explicitly defines all counters (except page counter) to be 'local' in columns, i.e. the values inside of paracol environment` are not transmitted to the outer document. If this is not wanted, \globalcounter{figure} (for example) is to be used in the preamble of the file. (See section 5.3 of the current paracol manual for more information on this) ...


2

Here is a way to achieve what you want... Use \addtocounter{algocf}{-1} to reduce the Algorithm counter before setting a countinued algorithm. Use \strut as part of the caption to ensure that they present at a similar height if you want to avoid a "jumping" effect when skipping between pages. Mark the end of an algorithm with a \label that you can use to ...


1

The \real macro seems to need arithmetics desperately, i.e. use 1*\real{19.95} etc. But it will be truncated anyway! \documentclass{article} \usepackage{siunitx} \usepackage{numprint} \usepackage{calc} \newcounter{foo} \begin{document} \addtocounter{foo}{5*\real{1.7}} \thefoo \end{document} Related: Is there a counter or variable that can be used ...


1

Why not? \documentclass{article} \newcounter{Temp} \newcounter{TestCounter} \setcounter{Temp}{5} \begin{document} \ifnum\theTemp>2 \setcounter{TestCounter}{4} \else \setcounter{TestCounter}{7} \fi \theTemp \theTestCounter \end{document}


1

You can do something like this: \makeatletter \newcount\tmpc@unter \newcount\LCount \LCount=2 \def\stepL{\global\advance\LCount1\relax} \def\theL{{\the\LCount}} \def\nextL{{\stepL\theL}} \def\refL#1{{\tmpc@unter=\LCount\advance\tmpc@unter#1\relax\the\tmpc@unter}} \makeatother \begin{document} $$L_\theL = L_\nextL + L_\nextL$$ and now: $$L_\refL{-2} = ...


1

I'm not sure I've understood the question, but I think the best approach is to save the label unformatted: \documentclass{article} \usepackage{enumitem} \makeatletter \newcommand\mylabel[2]{\mylabelfont{#1}\@arabic{#2}} \makeatother \let\mylabelfont\textsc % Default \newcommand\ucref[1]{% {\let\mylabelfont\MakeUppercase\ref{#1}}} \begin{document} ...


1

This looks like a typical “ask X for Y” question. @egreg has already explained why your approach with \edef is conceptually wrong. While he was posting his answer, I was trying to write down a workaround for what you seem to indicate, in a comment, as your original problem. I was ready to post the following attempt when I saw @egreg’s answer, essentially ...



Only top voted, non community-wiki answers of a minimum length are eligible