Tag Info

New answers tagged

1

For R users, an easy option is a file.Rnw file like that: <<echo=F>>= a <- 100 rounddown <- function(x){format(floor(x/a)*a, big.mark = ",")} @ \documentclass{article} \begin{document} Rounded down 2,326 is \Sexpr{rounddown(2326)}. \end{document} That with R CMD Sweave file.Rnw is converted to a true file.tex like that: ...


9

Here's a LuaLaTeX-based solution to the problem of truncating a number to the closest multiple of 100. Positive and negative numbers are both truncated toward zero. The \ensuremath macro, provided by the amsmath package, is used to make it unnecessary to keep track of whether the \mytrunc macro is used inside or outside of one of TeX's math mode ...


13

Use siunitx and expl3. \documentclass{article} \usepackage{xparse,siunitx} \ExplSyntaxOn \NewDocumentCommand{\hundreds}{O{}m} { \num[#1]{\fp_eval:n { trunc(#2,-2) }} } \ExplSyntaxOff \begin{document} \hundreds{2348} \hundreds[group-four-digits,group-separator={,}]{2348} \sisetup{group-four-digits,group-separator={,}} \hundreds{2348} ...


4

Just for fun with fp. Rounding \documentclass[preview,border=12pt,12pt,varwidth]{standalone} \usepackage[nomessages]{fp} \usepackage{pgffor} \newcommand\rounder[2]{\FPeval\x{round(round(#1*pow(-#2,10):0)*pow(#2,10):0)}\x} \begin{document} \begin{itemize} \foreach \i in {2440,2441,..., 2460}{\item \i\ is rounded to \rounder{\i}{2}.} \end{itemize} ...


4

\documentclass{article} \makeatletter \def\twodec#1{\expandafter\twodecB#1,,,\@nil} \def\twodecB#1,#2#3#4\@nil{\ifx,#2 #1,000\else#1,#200\fi} \makeatother \begin{document} \twodec{2}\par \twodec{2,3}\par \twodec{2,38}\par \twodec{2,386} \end{document}


5

Divide it by 100 then multiply the result by 100. \documentclass{article} \newcount\mycount \mycount = 2386 \divide\mycount by 100 \multiply\mycount by 100 \begin{document} \number\mycount \end{document}


2

You have to use the positioning-library of tikz to position nodes relative to each other. Try the follwing: \documentclass[tikz, border=5mm]{standalone} \usetikzlibrary{calc, positioning} \begin{document} \begin{tikzpicture} \node (p4) {$\hat{4}$}; \node[below=1cm of p4] (p3) {$3$}; \node[right=3cm of p4] (p1) {$\hat{1}$}; \node[below=1cm of p1] ...


2

You must: Add the positioning library. Use \pgfmathparse to calculate the 1/sqrt(2) expresion. Use \pgfmathresult where is the result of calculation. \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc,positioning} \begin{document} \begin{tikzpicture} \node (p4) {$\hat{4}$} ; \node[below=1cm of p4] (p3) {$3$} ; \node[right=3cm of p4] (p1) ...


3

Counters are, as you can see, also limited for such computations that involve borderline numbers for TeX. Preferably switch to fpu library, then you won't have any problems up to 2^324. And beyond that you should use proper tools not TeX anyway :) Here is a pretty big number handled by fpu. Recent L3 math can also cope with these if I remember correctly. ...


6

So if I was debugging this I'd add tracing so the MWE looked like \begin{document} \tracingmacros2 \tracingassigns2 Then run the MWE stopping at the error: ! Dimension too large. <to be read again> \relax l.39 } % ? x No pages of output. then look at the log file in an editor, starting from the error: ...


8

TeX is a macro expansion language and as such there is no stack trace: when a macro \foo is expanded to it's replacement text, the fact that this came from one macro rather than another or just by being part of the source directly is not recorded. Debugging TeX issues therefore requires a different approach using the tools TeX does provide. Probably the ...


4

The following explains and removes the problem of the test case. It's intended for people stumbling over the specific problem, but it's not an answer for the general case of debugging. The mathematical engine of pgf sees values without units as pt values. Therefore, you used 100000pt implicitly which caused the error. If you use a unit deliberatley (in ...



Top 50 recent answers are included