Home > Archive > Tex > September 2006 > Changing default measuring unit of TeX
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Changing default measuring unit of TeX
|
|
|
| All,
I am not sure if what I am asking is feasible or not but...
Can one change the default measuring unit of TeX from "pt" to any other
allowable unit like "bp", "mm", "in" etc.?
Thus if someone pass the \the\<dimen varialbe> then output should
appear in that newly set measuring unit. It would also be great if one
can have the flexibility of switching from one measuring unit to other
and again back or I should say vice versa.
| |
| Jonathan Fine 2006-09-26, 8:45 am |
| "david" <david_jsf@yahoo.com> wrote
> I am not sure if what I am asking is feasible or not but...
> Can one change the default measuring unit of TeX from "pt" to any other
> allowable unit like "bp", "mm", "in" etc.?
>
> Thus if someone pass the \the\<dimen varialbe> then output should
> appear in that newly set measuring unit. It would also be great if one
> can have the flexibility of switching from one measuring unit to other
> and again back or I should say vice versa.
Sorry to be picky, but in my view, TeX does not have a "default
measuring unit" for input.
===
$ tex
This is TeX, Version 3.141592 (MiKTeX 2.4)
**\dimen 0 = 10 \relax
! Illegal unit of measure (pt inserted).
<to be read again>
\relax
<*> \dimen 0 = 10 \relax
?
===
However, as you can see from above, it uses pt for error
recovery.
What you are asking for is another parameter, which is the
unit of measurement to be used when writing dimensions, say
to the log file.
Don Knuth, when he wrote TeX, wanted to create "just a
typesetting language" (Digital Typography, page 648).
Now, what advantages would your new feature bring?
On the demerit side, it would make log files harder
to parse.
--
Jonathan
| |
| Rolf Niepraschk 2006-09-26, 8:45 am |
| david schrieb:
> All,
>
> I am not sure if what I am asking is feasible or not but...
> Can one change the default measuring unit of TeX from "pt" to any other
> allowable unit like "bp", "mm", "in" etc.?
>
> Thus if someone pass the \the\<dimen varialbe> then output should
> appear in that newly set measuring unit. It would also be great if one
> can have the flexibility of switching from one measuring unit to other
> and again back or I should say vice versa.
>
If you're using LaTeX the following may help:
"printlen"
==> http://www.dante.de/CTAN/macros/lat...sc/printlen.sty
....Rolf
| |
|
|
Jonathan Fine wrote:
> "david" <david_jsf@yahoo.com> wrote
>
>
> Sorry to be picky, but in my view, TeX does not have a "default
> measuring unit" for input.
> ===
> $ tex
> This is TeX, Version 3.141592 (MiKTeX 2.4)
> **\dimen 0 = 10 \relax
> ! Illegal unit of measure (pt inserted).
> <to be read again>
> \relax
> <*> \dimen 0 = 10 \relax
>
> ?
> ===
>
> However, as you can see from above, it uses pt for error
> recovery.
>
Yes you are right, for input we can use whatever unit we want but
> What you are asking for is another parameter, which is the
> unit of measurement to be used when writing dimensions, say
> to the log file.
>
yes indeed I was asking about writing/displaying dimensions
> Don Knuth, when he wrote TeX, wanted to create "just a
> typesetting language" (Digital Typography, page 648).
>
> Now, what advantages would your new feature bring?
>
Suppose I am writing a program that is getting input from the user in
anyone of the unit and doing some pre-defined calculation and
displaying the output in the DVI file then what happens it gets
converted to default "pt" unit and if we are required to send the
output in same unit then again we will have to write a program to
convert it (the resulting output of \the command [pt value]) back and
then output that by removing pt unit in display using \remove@pt. If we
will be having any temporary switcing then for such applications we can
switch to the required unit.
> On the demerit side, it would make log files harder
> to parse.
definitely I am asking to change it globally, we can continue to write
it in pt value in log or any other auxiliary files, here also if
flexibity can given then it would be greatest.
your further suggestions or temporary solutions or temporary work
around for this would also be of great help.
David
>
> --
> Jonathan
| |
| Jonathan Fine 2006-09-26, 8:45 am |
| "Rolf Niepraschk" <Rolf.Niepraschk@gmx.de> wrote in message
news:efb84u$708$1@rzcomm2.rz.tu-bs.de...
> david schrieb:
>
> If you're using LaTeX the following may help:
>
> "printlen"
> ==> http://www.dante.de/CTAN/macros/lat...sc/printlen.sty
Interesting. I tried it out. It produces rounding errors.
More exactly, when a length is written out and then read
in again, the second value might not be equal to the first.
TeX's way of reading and writing points does not have this
problem.
Here's a minimal example of rounding error. BTW, perhaps
the documentation of printlen.sty should be revised to
take this into account. I'm not saying that this is a bug
in printlen, but the user might want to know about it.
===
$ latex
This is e-TeX, Version 3.141592-2.1 (MiKTeX 2.4)
**\makeatletter
entering extended mode
LaTeX2e <2001/06/01>
Babel <v3.7j> and hyphenation patterns for english, french, german, ngerman,
du
mylang, nohyphenation, loaded.
*\RequirePackage{printlen}
*
(C:\texmf\tex\latex\ltxmisc\printlen.sty)
(Please type a command or say `\end')
*\uselengthunit{mm}
*\showhyphens{\printlength{1in}}
Underfull \hbox (badness 10000) detected at line 0
[] \OT1/cmr/m/n/10 25.39969mm
*\dimen 0 1in \showthe\dimen 0
> 72.26999pt.
<*> \dimen 0 1in \showthe\dimen 0
?
*\dimen 0 25.39969mm \showthe\dimen 0
> 72.2691pt.
<*> \dimen 0 25.39969mm \showthe\dimen 0
?
*
===
--
Jonathan
| |
| David Kastrup 2006-09-26, 8:45 am |
| "david" <david_jsf@yahoo.com> writes:
> Suppose I am writing a program that is getting input from the user
> in anyone of the unit and doing some pre-defined calculation and
> displaying the output in the DVI file then what happens it gets
> converted to default "pt" unit and if we are required to send the
> output in same unit then again we will have to write a program to
> convert it (the resulting output of \the command [pt value]) back
> and then output that by removing pt unit in display using
> \remove@pt. If we will be having any temporary switcing then for
> such applications we can switch to the required unit.
You get rounding errors. Apart from that, writing your own \themm
command (as long as you are just outputting dimensions, not glue) is
not hard to do using eTeX:
\def\themm{\expandafter\themma\the}
\begingroup\catcode`P=12 \catcode`T=12
\lowercase{\endgroup
\def\themma#1PT{\expandafter\themmb\the\
dimexpr#1pt*2540/7227\relax mm}%
\def\themmb#1PT{#1}}
\dimen2=15mm
\message{\themm\dimen2}
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>
| |
|
|
David Kastrup wrote:
> "david" <david_jsf@yahoo.com> writes:
>
>
> You get rounding errors. Apart from that, writing your own \themm
> command (as long as you are just outputting dimensions, not glue) is
> not hard to do using eTeX:
>
> \def\themm{\expandafter\themma\the}
> \begingroup\catcode`P=12 \catcode`T=12
> \lowercase{\endgroup
> \def\themma#1PT{\expandafter\themmb\the\
dimexpr#1pt*2540/7227\relax mm}%
> \def\themmb#1PT{#1}}
> \dimen2=15mm
> \message{\themm\dimen2}
>
Thanks for workaround, but this might also have rounding errors and
this will also require to write the airthmatic for the each unit
conversion.
I was assuming that there might me some method which can allow to
set/change the default unit? Is there not any such option that can
change units without rounding errors...?
>
> --
> David Kastrup, Kriemhildstr. 15, 44793 Bochum
> UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>
| |
| Jean-Côme Charpentier 2006-09-26, 8:45 am |
| david a écrit :
> David Kastrup wrote:
>
>
>
> Thanks for workaround, but this might also have rounding errors
You can't avoid that. Even TeX do that:
\documentclass{minimal}
\begin{document}
\dimen0 1in
\the\dimen0
\end{document}
displays:
72.26999
but 1in is *exactly* 72.27pt (that's the point definition).
> and
> this will also require to write the airthmatic for the each unit
> conversion.
??? You see, TeX *does* arithmetic for display pt. Its internal unit
is sp, not pt.
> I was assuming that there might me some method which can allow to
> set/change the default unit?
No because there is no real needing.
> Is there not any such option that can
> change units without rounding errors...?
How can you avoid rounding errors ? You have to work with a infinity
sized numbers for that.
For example, when I said
\dimen0=1in
TeX translates this in sp unit (TeX don't know floating point numbers,
it knows just integer ones). You can see it with
\documentclass{minimal}
\begin{document}
\dimen0 1in
\count255 \dimen0
\the\count255
\end{document}
and TeX dispays
4736286
That means that, for TeX, 1in=4736286sp. Since 1sp=1/65536pt, and with
my beautiful pocket calculator, we have, 1in=72.26998901367188pt. That's
better... but that's still wrong!
You can't translate 1in in an integer multiple of sp. Then you'll
have always a rounding error.
Jean-Côme Charpentier
| |
| David Kastrup 2006-09-26, 8:45 am |
| "david" <david_jsf@yahoo.com> writes:
> David Kastrup wrote:
>
> Thanks for workaround, but this might also have rounding errors
Certainly. That's what I said.
> and this will also require to write the airthmatic for the each unit
> conversion.
The ratios are well-known.
@<Scan for \(a)all other units and adjust |cur_val| and |f|...@>=
if scan_keyword("in") then set_conversion(7227)(100)
@.in@>
else if scan_keyword("pc") then set_conversion(12)(1)
@.pc@>
else if scan_keyword("cm") then set_conversion(7227)(254)
@.cm@>
else if scan_keyword("mm") then set_conversion(7227)(2540)
@.mm@>
else if scan_keyword("bp") then set_conversion(7227)(7200)
@.bp@>
else if scan_keyword("dd") then set_conversion(1238)(1157)
@.dd@>
else if scan_keyword("cc") then set_conversion(14856)(1157)
@.cc@>
else if scan_keyword("sp") then goto done
@.sp@>
else @<Complain about unknown unit and |goto done2|@>;
cur_val:=xn_over_d(cur_val,num,denom);
f:=(num*f+@'200000*remainder) div denom;@/
cur_val:=cur_val+(f div @'200000); f:=f mod @'200000;
done2:
> I was assuming that there might me some method which can allow to
> set/change the default unit? Is there not any such option that can
> change units without rounding errors...?
Since the only units with an exact binary fraction representation are
"sp", "pt" and "pc", it is pretty illusory to work with other
dimensions sensibly. For example, 1mm+1mm in TeX is 5.69052pt,
whereas 2mm happens to be 5.69054pt.
If you want to preserve your sanity, externally processed variables
should be output with \number (namely as scaled point) and
calculations should be done on those integers exclusively.
Everything else is asking for trouble (even the decimal fractions
before pt are not exact, even though they are at least unique).
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
UKTUG FAQ: <URL:http://www.tex.ac.uk/cgi-bin/texfaq2html>
| |
|
| Thanks Mr. Jean and David,
Your suggestions are really very true...I admit the rounding and accept
to write a conversion. Even here I think "setspace" package option is
also good as rounding is the truth while adopting conversion.
I really appreciate the spirit that this user group have, I never get
disappointed from this group...
Jean-C=F4me Charpentier wrote:
> david a =E9crit :
m}%[color=darkred]
>
> You can't avoid that. Even TeX do that:
>
> \documentclass{minimal}
> \begin{document}
> \dimen0 1in
> \the\dimen0
> \end{document}
>
> displays:
>
> 72.26999
>
> but 1in is *exactly* 72.27pt (that's the point definition).
>
>
> ??? You see, TeX *does* arithmetic for display pt. Its internal unit
> is sp, not pt.
>
>
> No because there is no real needing.
>
>
> How can you avoid rounding errors ? You have to work with a infinity
> sized numbers for that.
> For example, when I said
> \dimen0=3D1in
> TeX translates this in sp unit (TeX don't know floating point numbers,
> it knows just integer ones). You can see it with
>
> \documentclass{minimal}
> \begin{document}
> \dimen0 1in
> \count255 \dimen0
> \the\count255
> \end{document}
>
> and TeX dispays
>
> 4736286
>
> That means that, for TeX, 1in=3D4736286sp. Since 1sp=3D1/65536pt, and with
> my beautiful pocket calculator, we have, 1in=3D72.26998901367188pt. That's
> better... but that's still wrong!
> You can't translate 1in in an integer multiple of sp. Then you'll
> have always a rounding error.
>=20
> Jean-C=F4me Charpentier
| |
|
|
david wrote:
> Thanks Mr. Jean and David,
> Your suggestions are really very true...I admit the rounding and accept
> to write a conversion. Even here I think "setspace" package option is
> also good as rounding is the truth while adopting conversion.
sorry I am correcting myself, i was talking about using "printlen.sty"
not "setspace.sty"
[color=darkred]
>
> I really appreciate the spirit that this user group have, I never get
> disappointed from this group...
>
> Jean-C=F4me Charpentier wrote:
mm}%[color=darkred]
ith[color=darkred]
t's[color=darkred]
| |
|
|
Jonathan Fine wrote:
> "Rolf Niepraschk" <Rolf.Niepraschk@gmx.de> wrote in message
> news:efb84u$708$1@rzcomm2.rz.tu-bs.de...
>
>
> Interesting. I tried it out. It produces rounding errors.
>
> More exactly, when a length is written out and then read
> in again, the second value might not be equal to the first.
>
> TeX's way of reading and writing points does not have this
> problem.
>
> Here's a minimal example of rounding error. BTW, perhaps
> the documentation of printlen.sty should be revised to
> take this into account. I'm not saying that this is a bug
> in printlen, but the user might want to know about it.
>
>
> ===
> $ latex
> This is e-TeX, Version 3.141592-2.1 (MiKTeX 2.4)
> **\makeatletter
> entering extended mode
> LaTeX2e <2001/06/01>
> Babel <v3.7j> and hyphenation patterns for english, french, german, ngerman,
> du
> mylang, nohyphenation, loaded.
>
> *\RequirePackage{printlen}
>
> *
> (C:\texmf\tex\latex\ltxmisc\printlen.sty)
> (Please type a command or say `\end')
> *\uselengthunit{mm}
>
> *\showhyphens{\printlength{1in}}
This is incorrect usage. You have to give \printlength a
length command (e.g., \parindent) or a length register
(e.g., \dimen0).
As used, it actually assigns to \@tempdimc the length 0.3514591in
(the text "0.351459", followed by the text "1in"), then prints out the
numerical part of its value in points followed by "mm".
If you tried "2in" you' would get the same result! ("25.39969mm")
But
\dimen0=2in
\showhyphens{\printlength{\dimen0}}
would produce approximately twice the amount.
Dan
|
|
|
|
|