Tag Info

New answers tagged

2

An expandable solution using the package bnumexpr for computations and \xintiloop for expandably looping with an index. \documentclass{article} \usepackage{bnumexpr}% minimally extends \numexpr to big integers (new on CTAN % as of 2014/09/22) % for \xintiloop: (for fun) \usepackage{xinttools}% automatically loaded by xint, which is ...


8

Two solutions. With Binet's formula \documentclass{article} \usepackage[paperwidth=3cm,paperheight=4cm,textheight=2cm]{geometry} \usepackage{xparse} \ExplSyntaxOn \fp_const:Nn \c_rudstep_phi_fp { (sqrt(5)+1)/2 } % the golden ratio \DeclareExpandableDocumentCommand{\fibonacci}{m} { \fp_eval:n { round( ( ( \c_rudstep_phi_fp)^(#1) - (1 - ...


14

Package fibnum helps: \usepackage{fibnum} \renewcommand*{\thepage}{\fibnum{\value{page}}} Full example: \documentclass{article} \usepackage{fibnum} \renewcommand*{\thepage}{\fibnum{\value{page}}} \begin{document} \newcommand*{\test}{% \begin{tabular}{ll} Page value: & \the\value{page}\\ \texttt{\textbackslash thepage}: & \thepage ...


2

Using my package calculator, you can perform arithmetic calculations comfortably. This code solves your problem: \documentclass{article} \usepackage{ifthen} \usepackage{calculator} \newcounter{n} \newcommand{\sumZeroToN}[2]{% \COPY{0}{#2} \whiledo{\not{\value{n}>#1}}{% \ADD{#2}{\value{n}}{#2}\stepcounter{n}}} \begin{document} ...


6

Using Lua is probably a huge overkill in this situation, but it shows off how one can easily integrate Lua in LaTeX. The code might also be easier to grasp for programmers who are beginners in LaTeX ;) % !TEX TS-program = lualatex % !TEX encoding = UTF-8 Unicode \documentclass{article} \usepackage[utf8]{luainputenc} \usepackage{luacode} % The code ...


2

Here is a short expl3 approach using \int_step_inline:nnnn. This carries out the explicit sum and doesn't rely on Gauss' reduction. So this is for illustration purposes only. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \cs_generate_variant:Nn \int_to_arabic:n { V } \cs_new:Npn \rudstep_sum:n #1 { \int_zero:N \l_tmpa_int ...


20

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 another difference (defaults 0 and 1). \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\arithmeticsequence}{sO{}m} { ...


11

\documentclass{article} \newcommand\foo[1]{\the\numexpr((#1)*(#1+1))/2\relax} % or if you want to print the terms \newcommand\foob[1]{$\fooc{#1}{0}=\foo{#1}$} \newcommand\fooc[2]{\the\numexpr#2\relax\ifnum#1=#2\relax\else+\fooc{#1}{\numexpr#2+1\relax}\fi} \begin{document} \foo{8} and \foo{5} \foob{8} and \foob{5} \end{document}


0

You have forgotten to include \usepackage{booktabs}. Your code could be: \documentclass{article} \usepackage{booktabs} \usepackage{spreadtab} \begin{document} \begin{spreadtab}{{tabular}{lcc}} \toprule @ Product name & @ Price & @ Count \\ \midrule @ product & 60 & 2\\ @ book & 90 & 4 \\ @ pen & 40 &10\\ @ other ...


2

Another solution, using my package calculator: command \LENGTHDIVIDE divides two lengths and returns a number. For example, \LENGTHDIVIDE{\newdashw}{\dashw}{\theRatio} \documentclass{article} \usepackage{calculator} % Load calculator \usepackage{fontspec} \setmainfont{TeX Gyre Schola} \def\hairspace{\kern .08333em} \newlength\dashw ...


0

You can compute expandably (hence as argument to \scalebox) using xintfrac \documentclass{article} \usepackage[showframe=true]{geometry} \usepackage{pst-node} \usepackage{graphicx} \usepackage{xintfrac} \begin{document} \noindent \scalebox{\xintRound {5}{\textwidth/\dimexpr 6cm\relax}}{% \begin{pspicture}(6,4) \pnode(2,2){A}\psframe(A) ...


2

You can use the expandable macros provided by package xintfrac \documentclass{article} \usepackage{fontspec} %\setmainfont{TeX Gyre Schola} % the font might change from doc to doc % on my installation, the fonts in TL tree must be made known via file name to % xetex \setmainfont[ExternalLocation]{texgyreschola-regular} \def\hairspace{\kern ...



Top 50 recent answers are included