I am doing a coursework in mechanics and would like to write both the theory and calculations in LaTeX. However, as design is iterative process, I would like to escape the tedious cycle of:

  1. Select starting values for diameters, lengths etc.
  2. Go through numerous steps, calculating derived values.
  3. The last step is stress-strength analysis and if that fails, go to step one.

Here is what I have got so far.

\usepackage[nomessages]{fp}  % http://ctan.org/pkg/fp
\usepackage[table]{xcolor}     % For coloured rows within tables.


\begin{tabular}{l | c | c | c | c | c | c | c | c}
Gear & $\alpha$ & $h_a$, [mm]             & c, [mm] & $h_f$, [mm] & $\rho$, [mm] & $h_w$, [mm] & h, [mm] & s, [mm] \\
G11  & \vAlpha  & \FPprint{vAlpha * 0.25} &         &             &              &             &         &          \\


As is evident, I am attempting to make calculations inside the table and directly display the result. It is not working (the third column is outputting nothing).

I know that \FPeval or \FPmul would work in this case, but I find them too cumbersome for the following reason. They both require me to assign the result to a variable, which I can later \FPprint. This is not very useful to me, as I would then need to compute a large number of variables and then invoke \FPprint inside the table.

I am not going to be using the computed result for anything else than displaying it in the table. All entries are a variable (different variables) multiplied by a constant. What is the best solution?

  • Using LaTeX to do calculations is like a dancing bear. What is impressing is not how well the bear dances, but that it dances at all. Sep 30, 2015 at 14:23
  • 2
    @JohnKormylo, could you propose a more efficient workflow. I have tried matlab and python scripts, to mix text and calculations . In those cases the bear dances masterfully, but is ugly as hell.
    – Vorac
    Sep 30, 2015 at 17:57
  • I tend to use C programs to calculate and create comma delimited files which I read using pgfplotstable. Sep 30, 2015 at 21:20
  • @JohnKormylo, thanks, I looked at the documentation of pgfplotstable and it seems a rather comprehensive package. You can expect a flurry of questions about it in a couple of weeks, when I find myself writing my graduation paper. Any reason why you prefer C to a higher-level language, e.g. python?
    – Vorac
    Nov 3, 2015 at 9:37

2 Answers 2

% Command to multiply a variale by a floating point number.
  \FPeval{vTemp}{#1 * #2}
  \FPround\vTemp{\vTemp}{4}  % Round to four digits after decimal point.

Not really a general solution, but work for the concrete question.


If you have R installed, you can use Sweave or knitr to put all mathematical operations from R in LaTeX. Save the MWE below with a .Rnw extension and compile with:

R CMD Sweave --pdf <filename>.Rnw

This make directly a <filename>.pdf. For more complex documents use Rstudio or in a terminal:

  • R CMD Sweave <filename>.Rnw
  • Then compile <filename>.tex as usual

The MWE:

G11  & \Sexpr{vAlpha=20;vAlpha} & \Sexpr{vAlpha * 0.25}  \\

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .