Hi,
how can I perform basic arithmetic calculations in plain TeX? For instance,
say I want some command "\fixedplusvarskip" that's supposed to set up a vskip
of at least some fixed value F, but ideally some size F+V, I would like to be
able to make a command as:
\newcommand{\fixedplusvarskip}[2]{\vskip{#1+#2}pt plus0pt minus#2pt}
but how do I get the calculation to work?
Similarly, say I want a skip that's only half of some indicated font size for
some text:
\newcommand{\textplushalfskip}[2]{\fontsize{#1pt}{{#1*1.2}pt}#2\vskip{#1/2}pt}
How do I get these multiplication/division evaluated?
Thanks,
- Mike "Pomax" Kamermans
nihongoresources.com
|
|
0
|
|
|
|
Reply
|
PmI (9)
|
12/15/2009 10:37:40 AM |
|
"PmI" <pmi@int13h.com> writes:
>how can I perform basic arithmetic calculations in plain TeX? For instance,
>say I want some command "\fixedplusvarskip" that's supposed to set up a vskip
>of at least some fixed value F, but ideally some size F+V, I would like to be
>able to make a command as:
>
>\newcommand{\fixedplusvarskip}[2]{\vskip{#1+#2}pt plus0pt minus#2pt}
>
>but how do I get the calculation to work?
>
>Similarly, say I want a skip that's only half of some indicated font size for
>some text:
>
>
>\newcommand{\textplushalfskip}[2]{\fontsize{#1pt}{{#1*1.2}pt}#2\vskip{#1/2}pt}
>
>How do I get these multiplication/division evaluated?
either write out the expression in terms of \advance, \divide,
\multiply using scratch registers, or look up etex \dimexpr --
requires a rather formalised sort of expression, but it's pretty
powerful.
there's also a \numexpr.
--
Robin Fairbairns, Cambridge
|
|
0
|
|
|
|
Reply
|
rf10
|
12/15/2009 11:28:49 AM
|
|
PmI <pmi@int13h.com> wrote:
> Hi,
>
> how can I perform basic arithmetic calculations in plain TeX? For instance,
> say I want some command "\fixedplusvarskip" that's supposed to set up a vskip
> of at least some fixed value F, but ideally some size F+V, I would like to be
> able to make a command as:
>
> \newcommand{\fixedplusvarskip}[2]{\vskip{#1+#2}pt plus0pt minus#2pt}
>
> but how do I get the calculation to work?
Is it plain TeX or LaTeX? Assuming a fairly recent LaTeX,
\newcommand{\fixedplusvarskip}[2]{%
\vskip\numexpr(#1+#2)pt plus 0pt minus #2pt}
I'd rather put the unit in the argument (perhaps you may want
ex instead of pt):
\newcommand{\fixedplusvarskip}[2]{%
\vskip\dimexpr(#1+#2) plus 0pt minus #2}
and \fixedplusvarskip{3ex}{1cm} would work without doing the math.
> Similarly, say I want a skip that's only half of some indicated font size for
> some text:
>
>
> \newcommand{\textplushalfskip}[2]{\fontsize{#1pt}{{#1*1.2}pt}#2\vskip{#1/2}pt}
>
> How do I get these multiplication/division evaluated?
\newcommand{\textplushalfskip}[2]{%
\fontsize{#1}{\dimexpr(#1*12/10)}\selectfont #2\vskip\dimexpr(#1/2)}
I'd rather use an environment for this one:
\newenvironment{plushalfskip}[1]
{\par\def\keeparg{#1}%
\fontsize{#1}{\dimexpr(#1*12/10)}\selectfont}
{\vskip\dimexpr(\keeparg/2)}
Ciao
Enrico
|
|
0
|
|
|
|
Reply
|
Enrico
|
12/15/2009 11:37:58 AM
|
|
Enrico Gregorio <gregorio@math.unipd.it> writes:
>PmI <pmi@int13h.com> wrote:
>> how can I perform basic arithmetic calculations in plain TeX? For instance,
>> say I want some command "\fixedplusvarskip" that's supposed to set up a vskip
>> of at least some fixed value F, but ideally some size F+V, I would like to be
>> able to make a command as:
>>
>> \newcommand{\fixedplusvarskip}[2]{\vskip{#1+#2}pt plus0pt minus#2pt}
>>
>> but how do I get the calculation to work?
>
>Is it plain TeX or LaTeX? Assuming a fairly recent LaTeX,
>
>\newcommand{\fixedplusvarskip}[2]{%
> \vskip\numexpr(#1+#2)pt plus 0pt minus #2pt}
>
>I'd rather put the unit in the argument (perhaps you may want
>ex instead of pt):
>
>\newcommand{\fixedplusvarskip}[2]{%
> \vskip\dimexpr(#1+#2) plus 0pt minus #2}
>
>and \fixedplusvarskip{3ex}{1cm} would work without doing the math.
>
>
>> Similarly, say I want a skip that's only half of some indicated font size for
>> some text:
>>
>>
>> \newcommand{\textplushalfskip}[2]{\fontsize{#1pt}{{#1*1.2}pt}#2\vskip{#1/2}pt}
>>
>> How do I get these multiplication/division evaluated?
>
>\newcommand{\textplushalfskip}[2]{%
> \fontsize{#1}{\dimexpr(#1*12/10)}\selectfont #2\vskip\dimexpr(#1/2)}
>
>I'd rather use an environment for this one:
>
>\newenvironment{plushalfskip}[1]
> {\par\def\keeparg{#1}%
> \fontsize{#1}{\dimexpr(#1*12/10)}\selectfont}
> {\vskip\dimexpr(\keeparg/2)}
last argument should be {\par\vskip\dimexpr(\keeparg/2)}
(as otherwise the baselineskip of the text of the enclosing paragraph
will be applied to the special text.
--
Robin Fairbairns, Cambridge
|
|
0
|
|
|
|
Reply
|
rf10
|
12/15/2009 12:02:23 PM
|
|
PmI a �crit :
> Hi,
>
> how can I perform basic arithmetic calculations in plain TeX? For instance,
> say I want some command "\fixedplusvarskip" that's supposed to set up a vskip
> of at least some fixed value F, but ideally some size F+V, I would like to be
> able to make a command as:
>
> \newcommand{\fixedplusvarskip}[2]{\vskip{#1+#2}pt plus0pt minus#2pt}
>
> but how do I get the calculation to work?
>
> Similarly, say I want a skip that's only half of some indicated font size for
> some text:
>
>
> \newcommand{\textplushalfskip}[2]{\fontsize{#1pt}{{#1*1.2}pt}#2\vskip{#1/2}pt}
>
> How do I get these multiplication/division evaluated?
>
> Thanks,
>
> - Mike "Pomax" Kamermans
> nihongoresources.com
For your purpose, I sugest you use the setspace package.
I am wrong ?
|
|
0
|
|
|
|
Reply
|
GL
|
12/15/2009 1:44:12 PM
|
|
Robin Fairbairns <rf10@cl.cam.ac.uk> wrote:
> >I'd rather use an environment for this one:
> >
> >\newenvironment{plushalfskip}[1]
> > {\par\def\keeparg{#1}%
> > \fontsize{#1}{\dimexpr(#1*12/10)}\selectfont}
> > {\vskip\dimexpr(\keeparg/2)}
>
> last argument should be {\par\vskip\dimexpr(\keeparg/2)}
> (as otherwise the baselineskip of the text of the enclosing paragraph
> will be applied to the special text.
A \vskip found in horizontal mode issues a \par automatically, and the
current paragraph has been started in the environment. :) There's a \par
in the opening code.
Not that I would really define and use environments such as this one. :)
Ciao
Enrico
|
|
0
|
|
|
|
Reply
|
Enrico
|
12/15/2009 1:51:21 PM
|
|
Enrico Gregorio <gregorio@math.unipd.it> wrote:
> PmI <pmi@int13h.com> wrote:
>
> \vskip\numexpr(#1+#2)pt plus 0pt minus #2pt}
>
> I'd rather put the unit in the argument (perhaps you may want
> ex instead of pt):
Disadvantage: \numexpr doesn't work with decimal numbers.
In this case:
\vskip#1\relax
\vskip#2 minus #2\relax
Or have I missed something?
Yours sincerely
Heiko <oberdiek@uni-freiburg.de>
|
|
0
|
|
|
|
Reply
|
Heiko
|
12/15/2009 2:15:30 PM
|
|
<<Disadvantage: \numexpr doesn't work with decimal numbers.
In this case:
\vskip#1\relax
\vskip#2 minus #2\relax
Or have I missed something?>>
My only concern is that I may have given too specific examples - the fontsize
command, for instance, also relies on some arithmetics being performed
(following the standard {<dim> }{1,2<dim>}), and there are other instances
where one might want to do simple arithmetics.
While the two step vskip solution works, for instance, it's a solution of
only the example code, rather than a general solution to doing arithmetics in
TeX (that is not to say I don't appreciate the vskip solution, it just
doesn't let me generalise the principle to arbitrary numbers).
- Mike
|
|
0
|
|
|
|
Reply
|
PmI
|
12/15/2009 2:33:53 PM
|
|
<<For your purpose, I sugest you use the setspace package.
I am wrong ?>>
The examples were purely that - the question remains how to do basic
arithmetic in TeX, not how to set specific spaces or how to set specific font
sizes. Can this be done? (without integer rounding messing up the result,
although if integer math is the only option, then integer math it has to be).
- Mike
|
|
0
|
|
|
|
Reply
|
PmI
|
12/15/2009 2:35:03 PM
|
|
On 15 Dez., 15:35, "PmI" <p...@int13h.com> wrote:
> <<For your purpose, I sugest you use the setspace package.
> I am wrong ?>>
>
> The examples were purely that - the question remains how to do basic
> arithmetic in TeX, not how to set specific spaces or how to set specific font
> sizes. Can this be done?
In that case I suggest the fp package. As far as I know it can be used
with plain TeX too.
Alexander
|
|
0
|
|
|
|
Reply
|
Alexander
|
12/15/2009 3:03:45 PM
|
|
Heiko Oberdiek <oberdiek@uni-freiburg.de> writes:
> Enrico Gregorio <gregorio@math.unipd.it> wrote:
>
>> PmI <pmi@int13h.com> wrote:
>>
>> \vskip\numexpr(#1+#2)pt plus 0pt minus #2pt}
>>
>> I'd rather put the unit in the argument (perhaps you may want
>> ex instead of pt):
>
> Disadvantage: \numexpr doesn't work with decimal numbers.
>
> In this case:
> \vskip#1\relax
> \vskip#2 minus #2\relax
>
> Or have I missed something?
Different effects on \lastskip? May sound academical, but has
repercussions with macros like \addvspace.
--
David Kastrup
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>
|
|
0
|
|
|
|
Reply
|
David
|
12/15/2009 3:27:24 PM
|
|
David Kastrup <dak@gnu.org> wrote:
> Heiko Oberdiek <oberdiek@uni-freiburg.de> writes:
>
> > Enrico Gregorio <gregorio@math.unipd.it> wrote:
> >
> >> PmI <pmi@int13h.com> wrote:
> >>
> >> \vskip\numexpr(#1+#2)pt plus 0pt minus #2pt}
> >>
> >> I'd rather put the unit in the argument (perhaps you may want
> >> ex instead of pt):
> >
> > Disadvantage: \numexpr doesn't work with decimal numbers.
> >
> > In this case:
> > \vskip#1\relax
> > \vskip#2 minus #2\relax
> >
> > Or have I missed something?
>
> Different effects on \lastskip?
Yes, thanks, I knew I had forgotten something, ...
Yours sincerely
Heiko <oberdiek@uni-freiburg.de>
|
|
0
|
|
|
|
Reply
|
Heiko
|
12/15/2009 4:41:12 PM
|
|
|
11 Replies
439 Views
(page loaded in 0.128 seconds)
Similiar Articles: Calculation Order ?? - comp.text.pdfI want to place a " in the calculation in order to do a literal find script. ... Calculation Order ?? - comp.text.pdf Date Range Calculation - comp.databases.filemaker ... Concatenate text from related records? - comp.databases.filemaker ...Question: is there a way to define a calculation field in the parent table that will concatenate text from several related child records? Bill -- To send e-mail ... ruby des encrypt - comp.lang.ruby... pad ($text, $blocksize) { $pad = $blocksize - (strlen($text ... encryption - How to perform Triple DES calculations in Ruby in ... I'm trying to do some triple DES ... Display number in text box - comp.soft-sys.matlabVisual C# .NET - Getting numbers from text boxes Text: Answer. Your form will then look like this: What we want to do is to get that number 10 from the text box and ... Matlab: Save pdf as txt? - comp.soft-sys.matlabThere seems to be no equivalent method that does what [jsObj.SaveAs SaveDir, "com.adobe.acrobat.plain-text"] does. Some advice would be very much appreciated! Using CM fonts in OS X **independent of TeX** - comp.text.tex ...I prepare PDFs on a MacBook running SnowLeopard, using TeXShop, pdftex, and Plain TeX from a vanilla installation of TUG's MacTeX 2010. My unders... FM7:Win32: counting instances of a value across fields - comp ...I know I'll need to use calculations to effect this, but I just can't work it out. ... wrote: > I have an additional question: is it possible to output as plain, readable text ... How to add jdom library into my jar file in eclipse - comp.lang ...Content-Type: text/plain; charset="gb2312" ..strongly indicates to me that it was always intended as 'text'. >..because not all news readers can handle it. how to draw an arc between two points given centre and radius ...But, the calculation fails if all three points are on the same line, as when drawing a ... Calculate pie Bezier control points - comp.text.pdf how to draw an arc between two ... Date Range Calculation - comp.databases.filemakerI would do this in FM6: create two globals in Invoices, for ... Calculation Order ?? - comp.text.pdf Date Range Calculation - comp.databases.filemaker Calculation ... quick problem - parsing text, calculation function... - comp ...quick problem - parsing text, calculation function... - comp ... This should be a relatively quick one... Basically I have a text field (input), into which I paste the ... Vehicle Mileage Tracker - comp.databases.filemakerThe fields are: Vehicle Name - Text Field Date - Date Field Odometer - Number ... as to how to > capture a vehicle's previous odometer reading in order to do the calculation ... How to compute RMS in frequency domain - comp.dspI do NOT want to transform signal to the time domain ... means in the frequency domain and the kind of calculation ... en.wikipedia.org/wiki/Replay_Gain- Hide quoted text ... comp.text.pdf - page 81This is page 81 of the comp.text.pdf group which contains 5549 articles. ... Perform calculations in a pdf ? 3 71 (1/9/2004 5:09:03 PM) Hi, is there a way to have some ... set a tikzpicture to a specific width - comp.text.tex[use as bounding box] will override the automatic bounding box calculation done by pgf ... HTH Itay <code> \documentclass{article} % Full width text ... How to Convert a Plain Text Document Into an Excel Spreadsheet ...At times, users may need to import data in plain text documents into Microsoft Excel so that they can perform calculations and other analysis using Microsoft Excel ... Perform Long Calculations in Plain English with These Awesome ...jailbreak Octopus Keyboard Adds BlackBerry-Style Predictive Text Typing to ... Perform Long Calculations in Plain English with These Awesome Calculator Apps 7/25/2012 8:41:55 PM
|