Guest User

Untitled

a guest
Nov 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.99 KB | None | 0 0
  1. makeatletter
  2. defconvertto#1#2{strip@ptdimexpr #2*65536/numberdimexpr 1#1}
  3. makeatother
  4.  
  5. documentclass[a4paper]{article}
  6.  
  7. usepackage{array}
  8. usepackage[hmargin=2cm]{geometry}
  9.  
  10. makeatletter
  11. %http://groups.google.com/group/comp.text.tex/msg/7e812e5d6e67fcc5
  12. defconvertto#1#2{strip@ptdimexpr #2*65536/numberdimexpr 1#1}
  13. makeatother
  14.  
  15. begin{document}
  16.  
  17. begin{center}begin{tabular}
  18. {>{defcolunit{pt}}l<{convertto{rowunit}{1colunit}}
  19. >{defcolunit{mm}}l<{convertto{rowunit}{1colunit}}
  20. >{defcolunit{cm}}l<{convertto{rowunit}{1colunit}}
  21. >{defcolunit{ex}}l<{convertto{rowunit}{1colunit}}
  22. >{defcolunit{em}}l<{convertto{rowunit}{1colunit}}
  23. >{defcolunit{bp}}l<{convertto{rowunit}{1colunit}}
  24. >{defcolunit{dd}}l<{convertto{rowunit}{1colunit}}
  25. >{defcolunit{pc}}l<{convertto{rowunit}{1colunit}}
  26. >{defcolunit{in}}l<{convertto{rowunit}{1colunit}}
  27. >{bfseries}l}
  28. 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} & \
  29. gdefrowunit{pt} & & & & & & & & & rowunit\
  30. gdefrowunit{mm} & & & & & & & & & rowunit\
  31. gdefrowunit{cm} & & & & & & & & & rowunit\
  32. gdefrowunit{ex} & & & & & & & & & rowunit\
  33. gdefrowunit{em} & & & & & & & & & rowunit\
  34. gdefrowunit{bp} & & & & & & & & & rowunit\
  35. gdefrowunit{dd} & & & & & & & & & rowunit\
  36. gdefrowunit{pc} & & & & & & & & & rowunit\
  37. gdefrowunit{in} & & & & & & & & & rowunit\
  38. end{tabular}end{center}
  39.  
  40. end{document}
  41.  
  42. documentclass{article}
  43. usepackage{printlen}
  44. parindent=0pt
  45.  
  46. newlengthLength Length=1cm
  47. begin{document}
  48.  
  49. tabular{p{2cm}p{2cm}}
  50. mbox{--- 1cm ---}
  51.  
  52. uselengthunit{cm}printlength{Length}
  53. uselengthunit{mm}printlength{Length}
  54. uselengthunit{in}printlength{Length}
  55. uselengthunit{pt}printlength{Length}
  56. uselengthunit{bp}printlength{Length}
  57. uselengthunit{sp}printlength{Length}
  58. uselengthunit{pc}printlength{Length}
  59. &
  60. mbox{--- 1em ---}
  61. Length=1em
  62. uselengthunit{cm}printlength{Length}
  63. uselengthunit{mm}printlength{Length}
  64. uselengthunit{in}printlength{Length}
  65. uselengthunit{pt}printlength{Length}
  66. uselengthunit{bp}printlength{Length}
  67. uselengthunit{sp}printlength{Length}
  68. uselengthunit{pc}printlength{Length}
  69. endtabular
  70. end{document}
  71.  
  72. documentclass{article}
  73.  
  74. usepackage{xintfrac}
  75. % http://www.ctan.org/tex-archive/macros/generic/xint
  76. % This code was compiled with the version 1.06a of the xint
  77. % bundle dated 2013/05/09, which should appear soon on CTAN.
  78. % The current CTAN version 1.06 should be also OK for this.
  79.  
  80. usepackage{array}
  81. usepackage[hmargin=.5cm]{geometry}
  82.  
  83. % Conversions to the basic dimension, chosen to be the centimeter
  84. % Base dimension: 1cm
  85. defonecm {1}
  86. defonemm {1/10}
  87. defonein {2.54}
  88. %% defonept {xintMul {1/72.27}{onein}}
  89. %% simpler:
  90. defonept {2.54/72.27}
  91. %% defonebp {xintMul {1/72}{onein}}
  92. %% simpler:
  93. defonebp {2.54/72}
  94. defonepc {xintMul {12}{onept}}
  95. defoneex {xintMul {thenumexprdimexpr 1exrelaxrelax}{onesp}}
  96. defoneem {xintMul {thenumexprdimexpr 1emrelaxrelax}{onesp}}
  97. defonedd {xintMul {1238/1157}{onept}}
  98. % 1157 dd = 1238 pt I take this conversion factor from the TeXBook
  99. % Wikipedia has other conversion factors, but of course here we
  100. % have to do it the TeX way.
  101. defonecc {xintMul {12}{onedd}}
  102. defonesp {xintMul {1/65536}{onept}}
  103.  
  104.  
  105. % Routines with delimited arguments, the good old TeX way
  106. % (completely expandable)
  107. makeatletter
  108.  
  109. % exact conversion to an irreducible fraction:
  110. % example: convertexactly 126.2772ptto {bp}
  111. % and `pt' may be a macro expanding to it.
  112. % idem for {bp} which may be a macro expanding to bp
  113. defconvertexactly #1to #2%
  114. {xintIrr{convertexactly@ #1to {#2}}}%
  115.  
  116. % Variant with rounding at a number of decimal places
  117. % given by first argument.
  118. defconvertwithrounding #1#2to #3%
  119. {xintRound {#1}{convertexactly@ #2to {#3}}}%
  120.  
  121. % routines doing the job:
  122.  
  123. defconvertexactly@ #1to
  124. {%
  125. romannumeral0%
  126. expandafterexpandafterexpandafter
  127. convertexactly@a
  128. xintReverseOrder {#1}Z
  129. }%
  130. defconvertexactly@a #1%
  131. {%
  132. ifcatnoexpand #1relax
  133. expandafter convertexactly@b
  134. else
  135. expandafter convertexactly@c
  136. fi #1%
  137. }%
  138. defconvertexactly@b #1#2Z #3%
  139. {%
  140. xintdiv {xintMul {xintReverseOrder{#2}}{csname one#1endcsname}}
  141. {csname one#3endcsname}%
  142. }%
  143. defconvertexactly@c #1#2#3Z #4%
  144. {%
  145. xintdiv {xintMul {xintReverseOrder{#3}}{csname one#2#1endcsname}}
  146. {csname one#4endcsname}%
  147. }%
  148.  
  149. makeatother
  150.  
  151. defbigstrut {vbox to 24pt{}vbox to 12pt{}}%
  152.  
  153. begin{document}
  154.  
  155. Testing:
  156.  
  157. 72.27pt is exactly convertexactly 72.27ptto {bp}bp
  158.  
  159. 1/2.54in is exactly convertexactly 1/2.54into {mm}mm
  160.  
  161. 10pt is exactly (for this font) convertexactly 10ptto {ex}ex,
  162. or approximately convertwithrounding{20}10ptto {ex}ex
  163.  
  164. 10pt is exactly (for this font) convertexactly 10ptto {em}em,
  165. or approximately convertwithrounding{20}10ptto {em}em
  166.  
  167. 1em is exactly (for this font) convertexactly
  168. 1emto {pt}pt, or approximately
  169. convertwithrounding{20}1emto {pt}pt.
  170.  
  171. And indeed
  172. verb+thedimexpr 1emrelax+ gives thedimexpr 1emrelax{} and
  173. verb+thefontdimen6font+ gives thefontdimen6font
  174.  
  175. 1ex is exactly (for this font) convertexactly 1exto {pt}pt, or approximately
  176. convertwithrounding{20}1exto {pt}pt.
  177.  
  178. And indeed
  179. verb+thedimexpr 1exrelax+ gives thedimexpr 1exrelax.
  180.  
  181. deftableentry{$displaystylexintFrac{convertexactly 1colunittorowunit}$bigstrut}
  182.  
  183. begin{center}begin{tabular}
  184. {>{defcolunit{pt}}l<{tableentry}
  185. >{defcolunit{mm}}l<{tableentry}
  186. >{defcolunit{cm}}l<{tableentry}
  187. >{defcolunit{ex}}l<{tableentry}
  188. >{defcolunit{em}}l<{tableentry}
  189. >{defcolunit{bp}}l<{tableentry}
  190. >{defcolunit{dd}}l<{tableentry}
  191. >{defcolunit{pc}}l<{tableentry}
  192. >{defcolunit{in}}l<{tableentry}
  193. >{bfseries}l}
  194. multicolumn{1}{l}{bfseries 1pt} & multicolumn{1}{l}{bfseries 1mm} &
  195. multicolumn{1}{l}{bfseries 1cm} & multicolumn{1}{l}{bfseries 1ex} &
  196. multicolumn{1}{l}{bfseries 1em} & multicolumn{1}{l}{bfseries 1bp} &
  197. multicolumn{1}{l}{bfseries 1dd} & multicolumn{1}{l}{bfseries 1pc} &
  198. multicolumn{1}{l}{bfseries 1in} & \
  199. gdefrowunit{pt} & & & & & & & & & rowunit\
  200. gdefrowunit{mm} & & & & & & & & & rowunit\
  201. gdefrowunit{cm} & & & & & & & & & rowunit\
  202. gdefrowunit{ex} & & & & & & & & & rowunit\
  203. gdefrowunit{em} & & & & & & & & & rowunit\
  204. gdefrowunit{bp} & & & & & & & & & rowunit\
  205. gdefrowunit{dd} & & & & & & & & & rowunit\
  206. gdefrowunit{pc} & & & & & & & & & rowunit\
  207. gdefrowunit{in} & & & & & & & & & rowunit\
  208. end{tabular}end{center}
  209.  
  210. clearpage
  211.  
  212. deftableentry{convertwithrounding {5}1colunittorowunit}
  213.  
  214. begin{center}begin{tabular}
  215. {>{defcolunit{pt}}l<{tableentry}
  216. >{defcolunit{mm}}l<{tableentry}
  217. >{defcolunit{cm}}l<{tableentry}
  218. >{defcolunit{ex}}l<{tableentry}
  219. >{defcolunit{em}}l<{tableentry}
  220. >{defcolunit{bp}}l<{tableentry}
  221. >{defcolunit{dd}}l<{tableentry}
  222. >{defcolunit{pc}}l<{tableentry}
  223. >{defcolunit{in}}l<{tableentry}
  224. >{bfseries}l}
  225. multicolumn{1}{l}{bfseries 1pt} & multicolumn{1}{l}{bfseries 1mm} &
  226. multicolumn{1}{l}{bfseries 1cm} & multicolumn{1}{l}{bfseries 1ex} &
  227. multicolumn{1}{l}{bfseries 1em} & multicolumn{1}{l}{bfseries 1bp} &
  228. multicolumn{1}{l}{bfseries 1dd} & multicolumn{1}{l}{bfseries 1pc} &
  229. multicolumn{1}{l}{bfseries 1in} & \
  230. gdefrowunit{pt} & & & & & & & & & rowunit\
  231. gdefrowunit{mm} & & & & & & & & & rowunit\
  232. gdefrowunit{cm} & & & & & & & & & rowunit\
  233. gdefrowunit{ex} & & & & & & & & & rowunit\
  234. gdefrowunit{em} & & & & & & & & & rowunit\
  235. gdefrowunit{bp} & & & & & & & & & rowunit\
  236. gdefrowunit{dd} & & & & & & & & & rowunit\
  237. gdefrowunit{pc} & & & & & & & & & rowunit\
  238. gdefrowunit{in} & & & & & & & & & rowunit\
  239. end{tabular}end{center}
  240.  
  241. end{document}
  242.  
  243. convertto{1in}{pt}
  244.  
  245. documentclass[a4paper]{article}
  246.  
  247. usepackage{array}
  248. usepackage[hmargin=2cm]{geometry}
  249.  
  250. usepackage{xparse}
  251. ExplSyntaxOn
  252. NewExpandableDocumentCommand{convertto}{smm}
  253. {
  254. egreg_convertto:nn {#2}{#3}
  255. IfBooleanT{#1}{#2}
  256. }
  257.  
  258. cs_new:Npn egreg_convertto:nn #1 #2
  259. {
  260. fp_eval:n { round( dim_to_decimal:n { #1 } / dim_to_decimal:n {1#2} , 5 ) }
  261. }
  262. ExplSyntaxOff
  263.  
  264. begin{document}
  265.  
  266. begin{center}begin{tabular}
  267. {>{defcolunit{pt}}l<{convertto{1colunit}{rowunit}}
  268. >{defcolunit{mm}}l<{convertto{1colunit}{rowunit}}
  269. >{defcolunit{cm}}l<{convertto{1colunit}{rowunit}}
  270. >{defcolunit{ex}}l<{convertto{1colunit}{rowunit}}
  271. >{defcolunit{em}}l<{convertto{1colunit}{rowunit}}
  272. >{defcolunit{bp}}l<{convertto{1colunit}{rowunit}}
  273. >{defcolunit{dd}}l<{convertto{1colunit}{rowunit}}
  274. >{defcolunit{pc}}l<{convertto{1colunit}{rowunit}}
  275. >{defcolunit{in}}l<{convertto{1colunit}{rowunit}}
  276. >{bfseries}l}
  277. multicolumn{1}{l}{bfseries 1pt} & multicolumn{1}{l}{bfseries 1mm} &
  278. multicolumn{1}{l}{bfseries 1cm} & multicolumn{1}{l}{bfseries 1ex} &
  279. multicolumn{1}{l}{bfseries 1em} & multicolumn{1}{l}{bfseries 1bp} &
  280. multicolumn{1}{l}{bfseries 1dd} & multicolumn{1}{l}{bfseries 1pc} &
  281. multicolumn{1}{l}{bfseries 1in} & \
  282. gdefrowunit{pt} & & & & & & & & & rowunit\
  283. gdefrowunit{mm} & & & & & & & & & rowunit\
  284. gdefrowunit{cm} & & & & & & & & & rowunit\
  285. gdefrowunit{ex} & & & & & & & & & rowunit\
  286. gdefrowunit{em} & & & & & & & & & rowunit\
  287. gdefrowunit{bp} & & & & & & & & & rowunit\
  288. gdefrowunit{dd} & & & & & & & & & rowunit\
  289. gdefrowunit{pc} & & & & & & & & & rowunit\
  290. gdefrowunit{in} & & & & & & & & & rowunit\
  291. end{tabular}end{center}
  292.  
  293. end{document}
  294.  
  295. documentclass[a4paper]{article}
  296.  
  297. usepackage{siunitx,array}
  298. usepackage[hmargin=1cm]{geometry}
  299. usepackage{xparse}
  300.  
  301. ExplSyntaxOn
  302.  
  303. seq_new:N g_egreg_convertto_units_seq
  304. seq_new:N l_egreg_convertto_temp_seq
  305. tl_new:N l_egreg_convertto_body_tl
  306.  
  307. seq_gset_from_clist:Nn g_egreg_convertto_units_seq
  308. {
  309. pt, mm, cm, ex, em, bp, dd, pc, in
  310. }
  311.  
  312. cs_new_protected:Nn __egreg_convertto_maketable:
  313. {
  314. seq_map_inline:Nn g_egreg_convertto_units_seq
  315. {
  316. seq_clear:N l_egreg_convertto_temp_seq
  317. seq_map_inline:Nn g_egreg_convertto_units_seq
  318. {
  319. seq_put_right:Nx l_egreg_convertto_temp_seq { egreg_convertto:nn { 1####1 } { ##1 } }
  320. }
  321. tl_put_right:Nx l_egreg_convertto_body_tl
  322. {
  323. seq_use:Nn l_egreg_convertto_temp_seq { & } & exp_not:n { textbf{##1} \ }
  324. }
  325. }
  326. seq_set_map:NNn l_egreg_convertto_temp_seq g_egreg_convertto_units_seq { {exp_not:N textbf{1,##1}} }
  327. }
  328.  
  329. NewDocumentCommand{maketable}{}
  330. {
  331. __egreg_convertto_maketable:
  332. begin{tabular}{*{seq_count:N g_egreg_convertto_units_seq}{S[table-format=2.5]}l}
  333. seq_use:Nn l_egreg_convertto_temp_seq { & } \
  334. l_egreg_convertto_body_tl
  335. end{tabular}
  336. }
  337.  
  338. NewExpandableDocumentCommand{convertto}{smm}
  339. {
  340. egreg_convertto:nn {#2}{#3}
  341. IfBooleanT{#1}{#2}
  342. }
  343.  
  344. cs_new:Npn egreg_convertto:nn #1 #2
  345. {
  346. fp_eval:n { round( dim_to_decimal:n { #1 } / dim_to_decimal:n {1#2} , 5 ) }
  347. }
  348. ExplSyntaxOff
  349.  
  350. begin{document}
  351.  
  352. begin{center}
  353. sisetup{group-digits=false}
  354. maketable
  355. end{center}
  356.  
  357. begin{center}
  358. begin{tabular}
  359. {>{defcolunit{pt}}l<{convertto{1colunit}{rowunit}}
  360. >{defcolunit{mm}}l<{convertto{1colunit}{rowunit}}
  361. >{defcolunit{cm}}l<{convertto{1colunit}{rowunit}}
  362. >{defcolunit{ex}}l<{convertto{1colunit}{rowunit}}
  363. >{defcolunit{em}}l<{convertto{1colunit}{rowunit}}
  364. >{defcolunit{bp}}l<{convertto{1colunit}{rowunit}}
  365. >{defcolunit{dd}}l<{convertto{1colunit}{rowunit}}
  366. >{defcolunit{pc}}l<{convertto{1colunit}{rowunit}}
  367. >{defcolunit{in}}l<{convertto{1colunit}{rowunit}}
  368. >{bfseries}l}
  369. multicolumn{1}{l}{bfseries 1pt} & multicolumn{1}{l}{bfseries 1mm} &
  370. multicolumn{1}{l}{bfseries 1cm} & multicolumn{1}{l}{bfseries 1ex} &
  371. multicolumn{1}{l}{bfseries 1em} & multicolumn{1}{l}{bfseries 1bp} &
  372. multicolumn{1}{l}{bfseries 1dd} & multicolumn{1}{l}{bfseries 1pc} &
  373. multicolumn{1}{l}{bfseries 1in} & \
  374. gdefrowunit{pt} & & & & & & & & & rowunit\
  375. gdefrowunit{mm} & & & & & & & & & rowunit\
  376. gdefrowunit{cm} & & & & & & & & & rowunit\
  377. gdefrowunit{ex} & & & & & & & & & rowunit\
  378. gdefrowunit{em} & & & & & & & & & rowunit\
  379. gdefrowunit{bp} & & & & & & & & & rowunit\
  380. gdefrowunit{dd} & & & & & & & & & rowunit\
  381. gdefrowunit{pc} & & & & & & & & & rowunit\
  382. gdefrowunit{in} & & & & & & & & & rowunit\
  383. end{tabular}end{center}
  384.  
  385. end{document}
  386.  
  387. documentclass[11pt]{article} % use larger type; default would be 10pt
  388. usepackage{xcolor}
  389. begin{document}
  390.  
  391. newdimentemp
  392.  
  393. defalength#1#2{
  394. temp#1
  395. nointerlineskip baselineskip=2pt
  396. vbox{hbox{hskip-29pttexttt{textcolor{#2}{#1=thetemp}}}
  397. hbox{vtop{color{#2}hrule width 130ptvspace{#1}hrule width 130pt}}%
  398. vspace{0.9cm}}
  399. }
  400.  
  401. alength{1cm}{blue}
  402. alength{1pc}{red}
  403. alength{1mm}{orange}
  404. alength{1cc}{red}
  405. alength{1dd}{red}
  406. alength{100000sp}{purple}
  407. alength{1in}{black}
  408. alength{1bp}{brown}
  409. alength{1em}{black}
  410. alength{1ex}{black}
  411. end{document}
  412.  
  413. documentclass{article}
  414. usepackage[T1]{fontenc}
  415. usepackage{mathpazo}
  416. newsaveboxCBox
  417. newlengthLength Length=1em
  418. begin{document}
  419.  
  420. sboxCBox{M}
  421. thewdCBox : theLength
  422.  
  423. tinyLength=1em
  424. sboxCBox{M}
  425. thewdCBox : theLength
  426.  
  427. HugeLength=1em
  428. sboxCBox{M}
  429. thewdCBox : theLength
  430.  
  431. end{document}
  432.  
  433. 1bp=numberdimexpr 1bprelax sp
  434.  
  435. 10bp=numberdimexpr 10bprelax sp
  436.  
  437. 100bp=numberdimexpr 100bprelax sp
  438.  
  439. 1000bp=numberdimexpr 1000bprelax sp
  440.  
  441. 10000bp=numberdimexpr 10000bprelax sp
  442.  
  443.  
  444. 1pt=numberdimexpr 1ptrelax sp
  445.  
  446. 10pt=numberdimexpr 10ptrelax sp
  447.  
  448. 100pt=numberdimexpr 100ptrelax sp
  449.  
  450. 1000pt=numberdimexpr 1000ptrelax sp
  451.  
  452. 10000pt=numberdimexpr 10000ptrelax sp
  453.  
  454. bye
  455.  
  456. 1bp/1pt=xintIrr{numberdimexpr 100bprelax/numberdimexpr 100ptrelax }
  457.  
  458. 72.27/72=xintIrr{72.27/72}
  459.  
  460. bye
Add Comment
Please, Sign In to add comment