# Tag Info

### Reducing fractions automatically using LaTeX3

Here is a flat LaTeX2e implementation. \documentclass{article} \usepackage{amsmath} \newcount{\numerator} \newcount{\denominator} \newcount{\gcd} % compute \gcd and returns reduced \numerator and \...
• 71.3k
Accepted

### Animate mass-spring-damper TikZ

Update: Wheel "riding" on the road and moving observer, as requested in OP and comments. (Click on the image to run the interactive SVG [3.9 MiB] in the browser.) The governing ODE system ...
• 51.8k

### Reducing fractions automatically using LaTeX3

If you are not bound to expl3 (in which case you “just” need to implement the algorithm): \documentclass{scrartcl} \usepackage{xintgcd,xintfrac} \newcommand*\reducedfrac[2] {\begingroup \edef\...
• 26.4k

### Reducing fractions automatically using LaTeX3

An option using Lua+LaTeX. Made small improvement. Made a Lua function to be called as a LaTeX command, with the numerator and denominator passed as arguments, instead of hardcoding the values in as ...
• 18.5k

### Simplifying square roots

Here's a LuaLaTeX-based solution. The code sets up a LaTeX macro named \rsqrt, which invokes a Lua function named rsqrt. The latter implements the simplification algorithm you've proposed -- with the ...
• 449k
Accepted

### Sum of finite series using LaTeX 3

Yes, you can, and pretty easily too. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\computesum}{mmm} {% pass control to an internal function \svend_compute_sum:nnn ...
• 1.0m
Accepted

### Reducing fractions automatically using LaTeX3

An expl3 implementation: \nonstopmode \input expl3-generic \relax \ExplSyntaxOn % -*- expl3 -*- \cs_new:Nn \svend_gcd:nn { \int_compare:nNnTF {#2} = { 0 } {#1} { \svend_gcd:ff {#2} { \...
• 26.9k
Accepted

### Drawing the three altitudes of a triangle with TikZ; incorrect orthocenter

This is, indeed, due to some inaccuracies in PGF, and can actually been seen in the manual in the section on coordinate calculations. More specifically it appears to be down to the the \...
• 69.2k

### simple arithmetic on index of foreach statement in tikz

Two solutions using only foreach own computing tools \foreach \x [count=\i] in {3.14,6.28,...,21.98} Difference between second and first items in list is calculate and added to second and ...
• 130k

### Sum of (example: 0+1+2+3 = 6 , 0+1+2+3+4+5+6+7 = 28 and so on)

The difficult task is generating the terms of the sequence, not computing the sum, of course; I present a macro that prints all the terms or just the sum. You can define a different starting point and ...
• 1.0m

### Longest Collatz sequence calculated with LaTeX

Reimplementation of Joseph's answer in LuaTeX. The nice thing about doing computations in Lua is that they are always fully-expandable. \documentclass{article} \usepackage{luacode} \begin{luacode} ...
• 106k

### How to get the sum, difference, product, and quotient from a macro in ConTeXt or Plain TeX?

You can use the ε-TeX primitive \numexpr for expandable integer expressions. The only restriction is that it won't work in engines without ε-TeX extensions (mostly Knuth TeX nowadays), ...
• 68.2k

### Simplifying square roots

In expl3: \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\rsqrt}{m} { \manual_rsqrt:n { #1 } } \int_new:N \l_manual_rsqrt_int \cs_new_protected:Nn \manual_rsqrt:...
• 1.0m

### How to transcript codes from HP 50G in LaTeX

This answer tries to reproduce the screenshot. It uses the lcd package, which defines an extended alphanumeric character set, with each character constructed using dots set in a 5 x 7 matrix. Thus, ...
• 5,451
Accepted

### Using LaTeX as calculator

Here's a solution that uses LuaLaTeX. No additional floating-point routines need be loaded. The output precision is controlled by the first argument of the string.format function; in the example below,...
• 449k

### Longest Collatz sequence calculated with LaTeX

I would do this using an expandable implementation: it's easy enough to keep everything on the stack: \documentclass{article} \usepackage{expl3} \usepackage{xparse} \begin{document} \ExplSyntaxOn \...
• 245k
Accepted

### How to make text appear in the middle of a phantom in math mode?

You don't really need to use \mathclap, you can just place what you want to center in a box of the appropriate width. \documentclass{article} \usepackage{amsmath} \usepackage{calc} \newcommand*{\mask}...
• 16.3k

### Page Numbering Using Only Fibonacci Numbers

• 263k
Accepted

### Total number of points

As long as you are just dealing with integer points, you can use a counter to sum them up. As you want to include the sum before they are actually added, the package totcount comes in handy: \...
Accepted

### How to compute the difference between two time points (e.g., 11:30 am and 01:20 pm => 110 min)?

\documentclass{article} \def\foo#1#2{% \the\numexpr(\xfoo#2\relax)-(\xfoo#1\relax)\relax\ minutes} \def\xfoo#1:#2 #3m#4\relax{% %(#1)*60+#2\if p#3+720 \fi (#1)*60+#2\if p#3\ifnum#1=12 \else+720\fi\...
• 680k

### Length plus minus other length?

Two alternatives to David's answer: e-TeX provides \glueexpr, which allows to add glue specifications: \newlength{\textsize} \makeatletter \setlength{\textsize}{\f@size pt} \makeatother \setlength{\...
• 263k

### Simplifying square roots

And here is an example how to do this using only classical TeX: \newcount\numA \newcount\numB \newcount\numC \newcount\numD \def\rsqrt#1{\numA=2 \numC=#1 \rsqrtA} \def\rsqrtA{% \numB=\numA \...
• 56.1k
Accepted

### Sort Numbers After Their Values

Easy with xparse and expl3: \documentclass{article} \usepackage{xparse,expl3} \ExplSyntaxOn \NewDocumentCommand{\sortnumberlist}{m} { \clist_set:Nn \l_svend_numberlist_clist { #1 } \clist_sort:...
• 1.0m
Accepted

### Tikz wrong calculation draw exponential function

This is caused by how the pgf math function exp is implemented. A simplified example: \documentclass{article} \usepackage{pgfmath, pgffor} \begin{document} \foreach \i in {8.9, 9.0, 9.1} { \...
• 22.9k
Accepted

### Rounding a number to its hundred

Use siunitx and expl3. \documentclass{article} \usepackage{xparse,siunitx} \ExplSyntaxOn \NewDocumentCommand{\hundreds}{O{}m} { \num[#1]{\fp_eval:n { trunc(#2,-2) }} } \ExplSyntaxOff \begin{...
• 1.0m

### Tikz: drawing in perspective

Another alternative from tikz-3dplot that provides more fun stuffs. Set the xyz coordinate system to xy coordinate system by \tdplotsetmaincoords{90}{90} Draw a large square first. Determine the ...
• 29.1k