Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- makeatletter
- defconvertto#1#2{strip@ptdimexpr #2*65536/numberdimexpr 1#1}
- makeatother
- documentclass[a4paper]{article}
- usepackage{array}
- usepackage[hmargin=2cm]{geometry}
- makeatletter
- %http://groups.google.com/group/comp.text.tex/msg/7e812e5d6e67fcc5
- defconvertto#1#2{strip@ptdimexpr #2*65536/numberdimexpr 1#1}
- makeatother
- begin{document}
- begin{center}begin{tabular}
- {>{defcolunit{pt}}l<{convertto{rowunit}{1colunit}}
- >{defcolunit{mm}}l<{convertto{rowunit}{1colunit}}
- >{defcolunit{cm}}l<{convertto{rowunit}{1colunit}}
- >{defcolunit{ex}}l<{convertto{rowunit}{1colunit}}
- >{defcolunit{em}}l<{convertto{rowunit}{1colunit}}
- >{defcolunit{bp}}l<{convertto{rowunit}{1colunit}}
- >{defcolunit{dd}}l<{convertto{rowunit}{1colunit}}
- >{defcolunit{pc}}l<{convertto{rowunit}{1colunit}}
- >{defcolunit{in}}l<{convertto{rowunit}{1colunit}}
- >{bfseries}l}
- multicolumn{1}{l}{bfseries 1pt} & multicolumn{1}{l}{bfseries 1mm} & multicolumn{1}{l}{bfseries 1cm} & multicolumn{1}{l}{bfseries 1ex} & multicolumn{1}{l}{bfseries 1em} & multicolumn{1}{l}{bfseries 1bp} & multicolumn{1}{l}{bfseries 1dd} & multicolumn{1}{l}{bfseries 1pc} & multicolumn{1}{l}{bfseries 1in} & \
- gdefrowunit{pt} & & & & & & & & & rowunit\
- gdefrowunit{mm} & & & & & & & & & rowunit\
- gdefrowunit{cm} & & & & & & & & & rowunit\
- gdefrowunit{ex} & & & & & & & & & rowunit\
- gdefrowunit{em} & & & & & & & & & rowunit\
- gdefrowunit{bp} & & & & & & & & & rowunit\
- gdefrowunit{dd} & & & & & & & & & rowunit\
- gdefrowunit{pc} & & & & & & & & & rowunit\
- gdefrowunit{in} & & & & & & & & & rowunit\
- end{tabular}end{center}
- end{document}
- documentclass{article}
- usepackage{printlen}
- parindent=0pt
- newlengthLength Length=1cm
- begin{document}
- tabular{p{2cm}p{2cm}}
- mbox{--- 1cm ---}
- uselengthunit{cm}printlength{Length}
- uselengthunit{mm}printlength{Length}
- uselengthunit{in}printlength{Length}
- uselengthunit{pt}printlength{Length}
- uselengthunit{bp}printlength{Length}
- uselengthunit{sp}printlength{Length}
- uselengthunit{pc}printlength{Length}
- &
- mbox{--- 1em ---}
- Length=1em
- uselengthunit{cm}printlength{Length}
- uselengthunit{mm}printlength{Length}
- uselengthunit{in}printlength{Length}
- uselengthunit{pt}printlength{Length}
- uselengthunit{bp}printlength{Length}
- uselengthunit{sp}printlength{Length}
- uselengthunit{pc}printlength{Length}
- endtabular
- end{document}
- documentclass{article}
- usepackage{xintfrac}
- % http://www.ctan.org/tex-archive/macros/generic/xint
- % This code was compiled with the version 1.06a of the xint
- % bundle dated 2013/05/09, which should appear soon on CTAN.
- % The current CTAN version 1.06 should be also OK for this.
- usepackage{array}
- usepackage[hmargin=.5cm]{geometry}
- % Conversions to the basic dimension, chosen to be the centimeter
- % Base dimension: 1cm
- defonecm {1}
- defonemm {1/10}
- defonein {2.54}
- %% defonept {xintMul {1/72.27}{onein}}
- %% simpler:
- defonept {2.54/72.27}
- %% defonebp {xintMul {1/72}{onein}}
- %% simpler:
- defonebp {2.54/72}
- defonepc {xintMul {12}{onept}}
- defoneex {xintMul {thenumexprdimexpr 1exrelaxrelax}{onesp}}
- defoneem {xintMul {thenumexprdimexpr 1emrelaxrelax}{onesp}}
- defonedd {xintMul {1238/1157}{onept}}
- % 1157 dd = 1238 pt I take this conversion factor from the TeXBook
- % Wikipedia has other conversion factors, but of course here we
- % have to do it the TeX way.
- defonecc {xintMul {12}{onedd}}
- defonesp {xintMul {1/65536}{onept}}
- % Routines with delimited arguments, the good old TeX way
- % (completely expandable)
- makeatletter
- % exact conversion to an irreducible fraction:
- % example: convertexactly 126.2772ptto {bp}
- % and `pt' may be a macro expanding to it.
- % idem for {bp} which may be a macro expanding to bp
- defconvertexactly #1to #2%
- {xintIrr{convertexactly@ #1to {#2}}}%
- % Variant with rounding at a number of decimal places
- % given by first argument.
- defconvertwithrounding #1#2to #3%
- {xintRound {#1}{convertexactly@ #2to {#3}}}%
- % routines doing the job:
- defconvertexactly@ #1to
- {%
- romannumeral0%
- expandafterexpandafterexpandafter
- convertexactly@a
- xintReverseOrder {#1}Z
- }%
- defconvertexactly@a #1%
- {%
- ifcatnoexpand #1relax
- expandafter convertexactly@b
- else
- expandafter convertexactly@c
- fi #1%
- }%
- defconvertexactly@b #1#2Z #3%
- {%
- xintdiv {xintMul {xintReverseOrder{#2}}{csname one#1endcsname}}
- {csname one#3endcsname}%
- }%
- defconvertexactly@c #1#2#3Z #4%
- {%
- xintdiv {xintMul {xintReverseOrder{#3}}{csname one#2#1endcsname}}
- {csname one#4endcsname}%
- }%
- makeatother
- defbigstrut {vbox to 24pt{}vbox to 12pt{}}%
- begin{document}
- Testing:
- 72.27pt is exactly convertexactly 72.27ptto {bp}bp
- 1/2.54in is exactly convertexactly 1/2.54into {mm}mm
- 10pt is exactly (for this font) convertexactly 10ptto {ex}ex,
- or approximately convertwithrounding{20}10ptto {ex}ex
- 10pt is exactly (for this font) convertexactly 10ptto {em}em,
- or approximately convertwithrounding{20}10ptto {em}em
- 1em is exactly (for this font) convertexactly
- 1emto {pt}pt, or approximately
- convertwithrounding{20}1emto {pt}pt.
- And indeed
- verb+thedimexpr 1emrelax+ gives thedimexpr 1emrelax{} and
- verb+thefontdimen6font+ gives thefontdimen6font
- 1ex is exactly (for this font) convertexactly 1exto {pt}pt, or approximately
- convertwithrounding{20}1exto {pt}pt.
- And indeed
- verb+thedimexpr 1exrelax+ gives thedimexpr 1exrelax.
- deftableentry{$displaystylexintFrac{convertexactly 1colunittorowunit}$bigstrut}
- begin{center}begin{tabular}
- {>{defcolunit{pt}}l<{tableentry}
- >{defcolunit{mm}}l<{tableentry}
- >{defcolunit{cm}}l<{tableentry}
- >{defcolunit{ex}}l<{tableentry}
- >{defcolunit{em}}l<{tableentry}
- >{defcolunit{bp}}l<{tableentry}
- >{defcolunit{dd}}l<{tableentry}
- >{defcolunit{pc}}l<{tableentry}
- >{defcolunit{in}}l<{tableentry}
- >{bfseries}l}
- multicolumn{1}{l}{bfseries 1pt} & multicolumn{1}{l}{bfseries 1mm} &
- multicolumn{1}{l}{bfseries 1cm} & multicolumn{1}{l}{bfseries 1ex} &
- multicolumn{1}{l}{bfseries 1em} & multicolumn{1}{l}{bfseries 1bp} &
- multicolumn{1}{l}{bfseries 1dd} & multicolumn{1}{l}{bfseries 1pc} &
- multicolumn{1}{l}{bfseries 1in} & \
- gdefrowunit{pt} & & & & & & & & & rowunit\
- gdefrowunit{mm} & & & & & & & & & rowunit\
- gdefrowunit{cm} & & & & & & & & & rowunit\
- gdefrowunit{ex} & & & & & & & & & rowunit\
- gdefrowunit{em} & & & & & & & & & rowunit\
- gdefrowunit{bp} & & & & & & & & & rowunit\
- gdefrowunit{dd} & & & & & & & & & rowunit\
- gdefrowunit{pc} & & & & & & & & & rowunit\
- gdefrowunit{in} & & & & & & & & & rowunit\
- end{tabular}end{center}
- clearpage
- deftableentry{convertwithrounding {5}1colunittorowunit}
- begin{center}begin{tabular}
- {>{defcolunit{pt}}l<{tableentry}
- >{defcolunit{mm}}l<{tableentry}
- >{defcolunit{cm}}l<{tableentry}
- >{defcolunit{ex}}l<{tableentry}
- >{defcolunit{em}}l<{tableentry}
- >{defcolunit{bp}}l<{tableentry}
- >{defcolunit{dd}}l<{tableentry}
- >{defcolunit{pc}}l<{tableentry}
- >{defcolunit{in}}l<{tableentry}
- >{bfseries}l}
- multicolumn{1}{l}{bfseries 1pt} & multicolumn{1}{l}{bfseries 1mm} &
- multicolumn{1}{l}{bfseries 1cm} & multicolumn{1}{l}{bfseries 1ex} &
- multicolumn{1}{l}{bfseries 1em} & multicolumn{1}{l}{bfseries 1bp} &
- multicolumn{1}{l}{bfseries 1dd} & multicolumn{1}{l}{bfseries 1pc} &
- multicolumn{1}{l}{bfseries 1in} & \
- gdefrowunit{pt} & & & & & & & & & rowunit\
- gdefrowunit{mm} & & & & & & & & & rowunit\
- gdefrowunit{cm} & & & & & & & & & rowunit\
- gdefrowunit{ex} & & & & & & & & & rowunit\
- gdefrowunit{em} & & & & & & & & & rowunit\
- gdefrowunit{bp} & & & & & & & & & rowunit\
- gdefrowunit{dd} & & & & & & & & & rowunit\
- gdefrowunit{pc} & & & & & & & & & rowunit\
- gdefrowunit{in} & & & & & & & & & rowunit\
- end{tabular}end{center}
- end{document}
- convertto{1in}{pt}
- documentclass[a4paper]{article}
- usepackage{array}
- usepackage[hmargin=2cm]{geometry}
- usepackage{xparse}
- ExplSyntaxOn
- NewExpandableDocumentCommand{convertto}{smm}
- {
- egreg_convertto:nn {#2}{#3}
- IfBooleanT{#1}{#2}
- }
- cs_new:Npn egreg_convertto:nn #1 #2
- {
- fp_eval:n { round( dim_to_decimal:n { #1 } / dim_to_decimal:n {1#2} , 5 ) }
- }
- ExplSyntaxOff
- begin{document}
- begin{center}begin{tabular}
- {>{defcolunit{pt}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{mm}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{cm}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{ex}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{em}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{bp}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{dd}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{pc}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{in}}l<{convertto{1colunit}{rowunit}}
- >{bfseries}l}
- multicolumn{1}{l}{bfseries 1pt} & multicolumn{1}{l}{bfseries 1mm} &
- multicolumn{1}{l}{bfseries 1cm} & multicolumn{1}{l}{bfseries 1ex} &
- multicolumn{1}{l}{bfseries 1em} & multicolumn{1}{l}{bfseries 1bp} &
- multicolumn{1}{l}{bfseries 1dd} & multicolumn{1}{l}{bfseries 1pc} &
- multicolumn{1}{l}{bfseries 1in} & \
- gdefrowunit{pt} & & & & & & & & & rowunit\
- gdefrowunit{mm} & & & & & & & & & rowunit\
- gdefrowunit{cm} & & & & & & & & & rowunit\
- gdefrowunit{ex} & & & & & & & & & rowunit\
- gdefrowunit{em} & & & & & & & & & rowunit\
- gdefrowunit{bp} & & & & & & & & & rowunit\
- gdefrowunit{dd} & & & & & & & & & rowunit\
- gdefrowunit{pc} & & & & & & & & & rowunit\
- gdefrowunit{in} & & & & & & & & & rowunit\
- end{tabular}end{center}
- end{document}
- documentclass[a4paper]{article}
- usepackage{siunitx,array}
- usepackage[hmargin=1cm]{geometry}
- usepackage{xparse}
- ExplSyntaxOn
- seq_new:N g_egreg_convertto_units_seq
- seq_new:N l_egreg_convertto_temp_seq
- tl_new:N l_egreg_convertto_body_tl
- seq_gset_from_clist:Nn g_egreg_convertto_units_seq
- {
- pt, mm, cm, ex, em, bp, dd, pc, in
- }
- cs_new_protected:Nn __egreg_convertto_maketable:
- {
- seq_map_inline:Nn g_egreg_convertto_units_seq
- {
- seq_clear:N l_egreg_convertto_temp_seq
- seq_map_inline:Nn g_egreg_convertto_units_seq
- {
- seq_put_right:Nx l_egreg_convertto_temp_seq { egreg_convertto:nn { 1####1 } { ##1 } }
- }
- tl_put_right:Nx l_egreg_convertto_body_tl
- {
- seq_use:Nn l_egreg_convertto_temp_seq { & } & exp_not:n { textbf{##1} \ }
- }
- }
- seq_set_map:NNn l_egreg_convertto_temp_seq g_egreg_convertto_units_seq { {exp_not:N textbf{1,##1}} }
- }
- NewDocumentCommand{maketable}{}
- {
- __egreg_convertto_maketable:
- begin{tabular}{*{seq_count:N g_egreg_convertto_units_seq}{S[table-format=2.5]}l}
- seq_use:Nn l_egreg_convertto_temp_seq { & } \
- l_egreg_convertto_body_tl
- end{tabular}
- }
- NewExpandableDocumentCommand{convertto}{smm}
- {
- egreg_convertto:nn {#2}{#3}
- IfBooleanT{#1}{#2}
- }
- cs_new:Npn egreg_convertto:nn #1 #2
- {
- fp_eval:n { round( dim_to_decimal:n { #1 } / dim_to_decimal:n {1#2} , 5 ) }
- }
- ExplSyntaxOff
- begin{document}
- begin{center}
- sisetup{group-digits=false}
- maketable
- end{center}
- begin{center}
- begin{tabular}
- {>{defcolunit{pt}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{mm}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{cm}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{ex}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{em}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{bp}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{dd}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{pc}}l<{convertto{1colunit}{rowunit}}
- >{defcolunit{in}}l<{convertto{1colunit}{rowunit}}
- >{bfseries}l}
- multicolumn{1}{l}{bfseries 1pt} & multicolumn{1}{l}{bfseries 1mm} &
- multicolumn{1}{l}{bfseries 1cm} & multicolumn{1}{l}{bfseries 1ex} &
- multicolumn{1}{l}{bfseries 1em} & multicolumn{1}{l}{bfseries 1bp} &
- multicolumn{1}{l}{bfseries 1dd} & multicolumn{1}{l}{bfseries 1pc} &
- multicolumn{1}{l}{bfseries 1in} & \
- gdefrowunit{pt} & & & & & & & & & rowunit\
- gdefrowunit{mm} & & & & & & & & & rowunit\
- gdefrowunit{cm} & & & & & & & & & rowunit\
- gdefrowunit{ex} & & & & & & & & & rowunit\
- gdefrowunit{em} & & & & & & & & & rowunit\
- gdefrowunit{bp} & & & & & & & & & rowunit\
- gdefrowunit{dd} & & & & & & & & & rowunit\
- gdefrowunit{pc} & & & & & & & & & rowunit\
- gdefrowunit{in} & & & & & & & & & rowunit\
- end{tabular}end{center}
- end{document}
- documentclass[11pt]{article} % use larger type; default would be 10pt
- usepackage{xcolor}
- begin{document}
- newdimentemp
- defalength#1#2{
- temp#1
- nointerlineskip baselineskip=2pt
- vbox{hbox{hskip-29pttexttt{textcolor{#2}{#1=thetemp}}}
- hbox{vtop{color{#2}hrule width 130ptvspace{#1}hrule width 130pt}}%
- vspace{0.9cm}}
- }
- alength{1cm}{blue}
- alength{1pc}{red}
- alength{1mm}{orange}
- alength{1cc}{red}
- alength{1dd}{red}
- alength{100000sp}{purple}
- alength{1in}{black}
- alength{1bp}{brown}
- alength{1em}{black}
- alength{1ex}{black}
- end{document}
- documentclass{article}
- usepackage[T1]{fontenc}
- usepackage{mathpazo}
- newsaveboxCBox
- newlengthLength Length=1em
- begin{document}
- sboxCBox{M}
- thewdCBox : theLength
- tinyLength=1em
- sboxCBox{M}
- thewdCBox : theLength
- HugeLength=1em
- sboxCBox{M}
- thewdCBox : theLength
- end{document}
- 1bp=numberdimexpr 1bprelax sp
- 10bp=numberdimexpr 10bprelax sp
- 100bp=numberdimexpr 100bprelax sp
- 1000bp=numberdimexpr 1000bprelax sp
- 10000bp=numberdimexpr 10000bprelax sp
- 1pt=numberdimexpr 1ptrelax sp
- 10pt=numberdimexpr 10ptrelax sp
- 100pt=numberdimexpr 100ptrelax sp
- 1000pt=numberdimexpr 1000ptrelax sp
- 10000pt=numberdimexpr 10000ptrelax sp
- bye
- 1bp/1pt=xintIrr{numberdimexpr 100bprelax/numberdimexpr 100ptrelax }
- 72.27/72=xintIrr{72.27/72}
- bye
Add Comment
Please, Sign In to add comment