# Tag Info

3

\usepackage{calc} ... \setlength{\msize}{0.5\paperwidth-0.5\textwidth} However, I recommend you looking at the hcentering option of the package geometry.

7

Use the e-TeX structure: \newlength{\msize} \setlength{\msize}{\dimexpr(\paperwidth-\textwidth)/2\relax} The macro \settowidth is used with finding the width of a portion of text such as in: \newlength{\mytextwidth} \settowidth{\mytextwidth}{This is some text whose width I'm measuring} The documentation can be found by running texdoc etex from the ...

3

Just use \begin{tabular}{p{\the\MyLen}@{}p{\the\MyLenTwo}@{}p{\the\MyLenThree}@{}} First&Second&Third \\ \end{tabular} As there is no flexibility in the glue between columns, tabular* can not change the width in any way, so the width using tabular* will be as for tabular but then forced into a box of the specified size, so generating a warning if ...

8

\documentclass{article} \usepackage{pst-plot} \usepackage{xparse} \ExplSyntaxOn%% allow _ : as a letter \newcommand\myMathFunction[1]{% \ifx#1x ((#1) * 5) - (#1)^2 \else \fp_to_decimal:n {((#1) * 5) - (#1)^2} \fi} \ExplSyntaxOff \begin{document} \begin{tabular}{ r r } $x$ & $f(x)$ \\\hline 0 & \myMathFunction{0}\\ 1 & \myMathFunction{1}\\ ...

10

Using PythonTeX: \documentclass{article} \usepackage{pythontex} \newcommand{\MyMathFunction}[1]{\py{2*(#1)**3 - 7}} \begin{document} \MyMathFunction{2} \end{document} Suppose the above is the content of the file my_math_fun_with_python.tex. You run LeTeX on the file: latex my_math_fun_with_latex then you run pythontex: pythontex.py ...

4

A much more general solution with the omnipotent Mathematica, LaTeX and PSTricks. In this answer I show how to evaluate a function, factor it into the product of linear real binomials, plot its graph. Step 1 Purchase Mathematica Home Edition (about USD \$250), download and install it. Step 2 Create a template named main.mtex (for example). The ...

5

Another solution with Maxima, a free computer algebra system. Note: Only for Windows users. Step 1 Download and install Maxima. Step 2 Create a batch file named cas.bat (for example) as follows. rem cas.bat echo off set PATH=%PATH%;"C:\Program Files (x86)\Maxima-5.31.2\bin" maxima --very-quiet -r %1 > solution.tex Save the batch in the same ...

12

Here's a solution using LuaLaTeX. The MWE provides a LaTeX macro called \MyMathFunction that interfaces with a Lua function called mymathfunction; the latter does the actual computations. % !TEX TS-program = lualatex \documentclass{article} \usepackage{fontspec} \usepackage{luacode} % for 'luacode' environment \usepackage{luatexbase} % for ...

4

The fp package provides a LaTeX2e-like interface to arithmetic: \documentclass{article} \usepackage[nomessages]{fp}% http://ctan.org/pkg/fp \newcommand{\myMathFunction}[1] {\FPeval\result{trunc(((#1) * 5) - (#1)^2:0)}\result} \begin{document} \verb|\myMathFunction{2}|: \myMathFunction{2} \end{document}

21

Here is a TikZ/PGF solution. I'm not sure how it compares to the l3fp approach, but it definitely offers more flexibility than a low-level TeX approach because it works in fixed-point arithmetic, not just with integers, and by using the right PGFkeys, you can easily customise how the result should be printed (trailing zeros, scientific notation, etc.). I ...

18

In good old (Plain) TeX, i.e., without LaTeX, with the proper TeX syntax: \documentclass{article} \begin{document} \newcount\pom % temporary \newcount\kw % square \newcount\first % first \def\myMathFunction#1{\pom#1 \first\pom \kw\pom \multiply\kw by\pom \multiply\first by5 \advance\first by-\kw \the\first} \myMathFunction{2} And an example of ...

21

Remarks I used the powerful LaTeX3 featureset l3fp, which is automatically loaded by xparse. Implementation \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\myMathFunction}{m} { \fp_to_decimal:n {((#1) * 5) - (#1)^2} } \ExplSyntaxOff \begin{document} \myMathFunction{2} \end{document}

3

You can calculate the intersection of two non-parallel lines using the coordinate specification (intersection of A--B and C--D), where A, B, C and D have to be named nodes. That's the approach used in the code you linked to. This, however, does not work with arbitrary named paths, which is what you're trying to do. To calculate the intersections of a line ...

0

Why did nobody suggest the dozenal package on CTAN?

2

My first thought: With luaLaTeX it should be quite easy. Here it is: \documentclass{scrartcl} \usepackage{siunitx} \newcommand{\temperature}[1]{\SI{\directlua{tex.sprint(#1+273.15)}}{\kelvin} (\SI{#1}{\celsius})} \begin{document} \temperature{100} \end{document} I replaced your #1+273 with \directlua{tex.sprint(#1+273.15)}.

4

To each his/her favourite math engine... Update: using \xinttheexpr...\relax for infix notations. But it doesn't seem that \SI does a full expansion immediately, it first apparently parses for ( and ) among others. So I had to do a little trick with a \firstofone. \documentclass{article} \usepackage{siunitx,xintexpr} \providecommand\firstofone ...

8

You can calculate the expression #1+273 outside \SI and use it. To calculate you can use your preferred method. I chose pgf. \documentclass{article} \usepackage{siunitx,pgf} \newcommand*{\temperature}[1]{\pgfmathtruncatemacro{\temp}{#1+273}\SI{\temp}{\kelvin} (\SI{#1}{\celsius})} %no truncation ...

15

You can use the l3fp module of expl3: \documentclass{article} \usepackage{siunitx} % already loads xparse \ExplSyntaxOn \NewDocumentCommand{\temperature}{ O{0} m } { \bryebex_temperature:nn { #1 } { #2 } } \cs_new_protected:Npn \bryebex_temperature:nn #1 #2 { \SI{ \fp_to_decimal:n { round ( #2+273.15, #1 ) } } { \kelvin } \nobreakspace ( \SI { #2 ...

6

You need to create a length (here, \myfntht), so that the multiply can be easily done. I EDITED the answer to allow an optional parameter as the multiplier between the two arguments of the \fontsize macro. Note that, while I used multipliers of \baselineskip to set the new font size in my MWE, it is probably best to use another measure, as \baselineskip is ...

Top 50 recent answers are included