diff options
author | Karl Berry <karl@freefriends.org> | 2020-05-07 21:27:27 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2020-05-07 21:27:27 +0000 |
commit | 4f11b4d0bdb77414ff4011c754536656f7708bf0 (patch) | |
tree | 3c118dfe94ed718aa12cd55783b9a69cba86a9bd /Master/texmf-dist | |
parent | 5fc116fc34329b711fe6a8a155f71c42a5ff03c7 (diff) |
unitconv (7may20)
git-svn-id: svn://tug.org/texlive/trunk@55060 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/lualatex/unitconv/Changes | 1 | ||||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/unitconv/README.md | 16 | ||||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/unitconv/unitconv-doc.pdf | bin | 0 -> 69514 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/unitconv/unitconv-doc.tex | 216 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/unitconv/unitconv.sty | 128 |
5 files changed, 361 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/lualatex/unitconv/Changes b/Master/texmf-dist/doc/lualatex/unitconv/Changes new file mode 100644 index 00000000000..bf2c7386aa1 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/unitconv/Changes @@ -0,0 +1 @@ +0.01 2020-05-07 - first CTAN version diff --git a/Master/texmf-dist/doc/lualatex/unitconv/README.md b/Master/texmf-dist/doc/lualatex/unitconv/README.md new file mode 100644 index 00000000000..8bef4b5b655 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/unitconv/README.md @@ -0,0 +1,16 @@ +# README # +Package unitconv can conver t a TeX length or a given +value with unit into another unit, Supported are all +TeX units and also m and km. The output can be in +scientic notation for large values. + +This package needs lualatex! + +% This file is distributed under the terms of the LaTeX Project Public +% License from CTAN archives in directory macros/latex/base/lppl.txt. +% Either version 1.3 or, at your option, any later version. +% +% Copyright 2020 Herbert Voss hvoss@tug.org +% + +%% $Id: README.md 1177 2020-05-07 15:38:43Z herbert $ diff --git a/Master/texmf-dist/doc/lualatex/unitconv/unitconv-doc.pdf b/Master/texmf-dist/doc/lualatex/unitconv/unitconv-doc.pdf Binary files differnew file mode 100644 index 00000000000..6932069f0d5 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/unitconv/unitconv-doc.pdf diff --git a/Master/texmf-dist/doc/lualatex/unitconv/unitconv-doc.tex b/Master/texmf-dist/doc/lualatex/unitconv/unitconv-doc.tex new file mode 100644 index 00000000000..c0dfa1de4b1 --- /dev/null +++ b/Master/texmf-dist/doc/lualatex/unitconv/unitconv-doc.tex @@ -0,0 +1,216 @@ +%% $Id: unitconv-doc.tex 1177 2020-05-07 15:38:43Z herbert $ +\listfiles +\documentclass[english,parskip=half]{scrartcl} +\usepackage{libertinus} +\setmonofont[Scale=MatchLowercase,FakeStretch=0.9]{AnonymousPro} +\usepackage{babel} +\usepackage[autostyle]{csquotes} + +\usepackage{unitconv} +\usepackage{showexpl,xltabular,nicefrac,booktabs} +\lstset{basicstyle=\ttfamily\small} + +\title{Convert a length into one with another unit +with Lua\TeX} +\author{Herbert Voß} +\parindent=0pt + +\begin{document} +\maketitle +\tableofcontents +\section{Using} + +\begin{verbatim} +\usepackage{unitconv} +\end{verbatim} + + +\section{Macros} + +\begin{verbatim} +\convTeXLength*[<unit>][<digits>]{<TeX length>} +\convLength*[<unit>][<digits>]{<value>}[<unit>] +\end{verbatim} + +The star version prints the number in scientific notation. +The default setting for the unit is \verb|cm| +and for the number of digits \verb|-1| (print all digits). +The dynamic units \verb|em|, \verb|ex|, and \verb|mu| depend on the +current fontsize. + +\begin{itemize} +\item This package works only with \verb|lualatex|! +\item With \textsf{AmsMath} you have to load the package before \texttt{unitconv}. +\end{itemize} + + +\section{The units} + +\def\Index#1{#1}% +\begin{tabular}{@{}>{\bfseries\ttfamily}c l @{}}\toprule +\rmfamily\normalfont\emph{Short}& \emph{Long} \\\midrule +\Index{bp} & Big Point (72\,bp/in) \\ +\Index{cc} & Cîcero (1\,cc=12\,dd) \\ +\Index{cm} & Centimeter \\ +\Index{dd} & Didôt ($1157\,\mathrm{dd}=1238\,\mathrm{pt}$) \\ +\Index{em} & Width of »M« in the current font \\ +\Index{ex} & Height of »x« in the current font \\ +\Index{in} & Inch (72.27\,pt) \\ +\Index{km} & Kilometer \\ +\Index{m} & Meter \\ +\Index{mm} & Millimeter \\ +\Index{mu} & Math unit (1\,mu=\nicefrac{1}{18}em) \\ +\Index{pc} & Pica (12\,pt/pc) \\ +\Index{pt} & (\TeX-)Points ($\nicefrac{1}{72.27}$\,Inch) \\ +\Index{px} & Pixel, 1\,px=\nicefrac{1}{72}in (pdf\TeX)\\ +\Index{sp} & Scaled Point (65536\,sp/pt) \\ +\bottomrule +\end{tabular} + + +\section{Examples} +\subsection{Converting a \TeX\ length} + +\begin{LTXexample}[width=0.5\linewidth] +The current example linewidth is +\the\linewidth, which is + +\convTeXLength{\linewidth}\\ +\convTeXLength[bp]{\linewidth}\\ +\convTeXLength[cc]{\linewidth}\\ +\convTeXLength[dd]{\linewidth}\\ +\convTeXLength[em]{\linewidth}\\ +\convTeXLength[ex]{\linewidth}\\ +\convTeXLength[in]{\linewidth}\\ +\convTeXLength[km]{\linewidth}\\ +\convTeXLength[m]{\linewidth}\\ +\convTeXLength[mm]{\linewidth}\\ +\convTeXLength[mu]{\linewidth}\\ +\convTeXLength[pc]{\linewidth}\\ +\convTeXLength[pt]{\linewidth}\\ +\convTeXLength[px]{\linewidth}\\ +\convTeXLength*[sp]{\linewidth} +\end{LTXexample} + +\begin{LTXexample}[width=0.5\linewidth] +The current character width of M +is 1\,em, which is + +\convTeXLength{1em}\\ +\convTeXLength[bp]{1em}\\ +\convTeXLength[cc]{1em}\\ +\convTeXLength[dd]{1em}\\ +\convTeXLength[em]{1em}\\ +\convTeXLength[ex]{1em}\\ +\convTeXLength[in]{1em}\\ +\convTeXLength[km]{1em}\\ +\convTeXLength[m]{1em}\\ +\convTeXLength[mm]{1em}\\ +\convTeXLength[mu]{1em}\\ +\convTeXLength[pc]{1em}\\ +\convTeXLength[pt]{1em}\\ +\convTeXLength[px]{1em}\\ +\convTeXLength*[sp]{1em} +\end{LTXexample} + + +\begin{LTXexample}[width=0.5\linewidth] +The current example linewidth is +\the\linewidth, which is + +\convTeXLength[bp][3]{\linewidth}\\ +\convTeXLength[cc][3]{\linewidth}\\ +\convTeXLength[cm][3]{\linewidth}\\ +\convTeXLength[dd][3]{\linewidth}\\ +\convTeXLength[em][3]{\linewidth}\\ +\convTeXLength[ex][3]{\linewidth}\\ +\convTeXLength[in][3]{\linewidth}\\ +\convTeXLength[km][3]{\linewidth}\\ +\convTeXLength[m][3]{\linewidth}\\ +\convTeXLength[mm][3]{\linewidth}\\ +\convTeXLength[mu][3]{\linewidth}\\ +\convTeXLength[pc][3]{\linewidth}\\ +\convTeXLength[pt][3]{\linewidth}\\ +\convTeXLength[px][3]{\linewidth}\\ +\convTeXLength*[sp][3]{\linewidth} +\end{LTXexample} + +\begin{LTXexample}[width=0.5\linewidth] +The current width of the letter M is +1\,em, which is + +\convTeXLength[bp][3]{1em}\\ +\convTeXLength[cc][3]{1em}\\ +\convTeXLength[cm][3]{1em}\\ +\convTeXLength[dd][3]{1em}\\ +\convTeXLength[em][3]{1em}\\ +\convTeXLength[ex][3]{1em}\\ +\convTeXLength[in][3]{1em}\\ +\convTeXLength[km][3]{1em}\\ +\convTeXLength[m][3]{1em}\\ +\convTeXLength[mm][3]{1em}\\ +\convTeXLength[mu][3]{1em}\\ +\convTeXLength[pc][3]{1em}\\ +\convTeXLength[pt][3]{1em}\\ +\convTeXLength[px][3]{1em}\\ +\convTeXLength*[sp][3]{1em} +\end{LTXexample} + +\begin{LTXexample}[width=0.5\linewidth] +The current example linewidth is +\the\linewidth, which is + +\convTeXLength[bp][-1]{\linewidth}\\ +\convTeXLength[cc][0]{\linewidth}\\ +\convTeXLength[cm][1]{\linewidth}\\ +\convTeXLength[dd][2]{\linewidth}\\ +\convTeXLength[em][3]{\linewidth}\\ +\convTeXLength[ex][4]{\linewidth}\\ +\convTeXLength[in][5]{\linewidth}\\ +\convTeXLength[km][6]{\linewidth}\\ +\convTeXLength[m][7]{\linewidth}\\ +\convTeXLength[mm][8]{\linewidth}\\ +\convTeXLength[mu][9]{\linewidth}\\ +\convTeXLength[pc][10]{\linewidth}\\ +\convTeXLength[pt][11]{\linewidth}\\ +\convTeXLength[px][12]{\linewidth}\\ +\convTeXLength*[sp][13]{\linewidth} +\end{LTXexample} + + + +\begin{LTXexample}[width=0.5\linewidth] +\convTeXLength[em][2]{1}\\ % default is cm +\convTeXLength[em][2]{2}\\ +\convTeXLength[em][2]{3} +\end{LTXexample} + + + +\begin{LTXexample}[width=0.5\linewidth] +The current example linewidth is +\the\linewidth, which is + +\convTeXLength[em][2]{\linewidth}\\ +\convTeXLength[ex][2]{\linewidth}\\ +\convTeXLength[mu][2]{\linewidth} + +\Huge Test\\ +\convTeXLength[em][2]{\linewidth}\\ +\convTeXLength[ex][2]{\linewidth}\\ +\convTeXLength[mu][2]{\linewidth} +\end{LTXexample} + +\subsection{Converting a value with given unit into another one} + +\begin{LTXexample}[width=0.5\linewidth] +\convLength[m]{1.2345}[km]\\ +\convLength[cm]{1.2345}[km]\\ +\convLength*[mm]{1.2345}[km]\\ +\convLength[bp]{1.2345}[km]\\ +\convLength[km][4]{3499402.985833}[bp] +\end{LTXexample} + + + +\end{document} diff --git a/Master/texmf-dist/tex/lualatex/unitconv/unitconv.sty b/Master/texmf-dist/tex/lualatex/unitconv/unitconv.sty new file mode 100644 index 00000000000..9a16dcd2c9f --- /dev/null +++ b/Master/texmf-dist/tex/lualatex/unitconv/unitconv.sty @@ -0,0 +1,128 @@ +%% $Id: unitconv.sty 1177 2020-05-07 15:38:43Z herbert $ +%% +%% This file is distributed under the terms of the LaTeX Project Public +%% License from CTAN archives in directory macros/latex/base/lppl.txt. +%% Either version 1.3 or, at your option, any later version. +%% +% +% Copyright 2020 Herbert Voss hvoss@tug.org +% +\RequirePackage{iftex,xparse,luacode} +\ProvidesPackage{unitconv}[% + 2020/05/07 v. 0.01 (Herbert Voss) Supports unit conversion of a length (only lualatex)] + +\ifluatex +\else + \ExplSyntaxOn + \msg_new:nnn {unitconv} {need-lualatex} + { + The~ unitconv~ package~ requires~ LuaLaTeX.\\\\ + You~ must~ change~ your~ typesetting~ engine~ to,~ + "lualatex" instead~ of~ "latex", ~"pdflatex",~ or~ + "xelatex". + } + \msg_fatal:nn {unitconv} {need-lualatex} + \ExpSyntaxOff + \endinput +\fi + +\newif\ifconv@Scientific + +\providecommand\text{\mbox} + +\begin{luacode} + convList = { ["bp"] = 1.00374, -- 1bp = 1.00374pt + ["cc"] = 12.8401, + ["cm"] = 28.45274, -- 1cm = 28.45274pt + ["dd"] = 1.07, + ["em"] = 10, + ["ex"] = 4.37, + ["in"] = 72.27, + ["km"] = 2.845274e6, + ["m"] = 2845.274, + ["mm"] = 2.84526, + ["mu"] = 0.05554, + ["pc"] = 12.0, + ["pt"] = 1.0, + ["px"] = 1.00374, + ["sp"] = 0.00005 } +\end{luacode} + +\def\convLength{\@ifnextchar*{\global\conv@Scientifictrue\conv@Length}{\global\conv@Scientificfalse\conv@Length*}} +\def\conv@Length*{\@ifnextchar[\convLength@i{\convLength@i[cm]}}% [unit] +\def\convLength@i[#1]{\@ifnextchar[{\convLength@ii[#1]}{\convLength@ii[#1][-1]}} +\def\convLength@ii[#1][#2]#3{\convLen@iii{#3}{#1}{#2}} + +\def\convTeXLength{\@ifnextchar*{\global\conv@Scientifictrue\conv@TeXLength}{\global\conv@Scientificfalse\conv@TeXLength*}} +\def\conv@TeXLength*{\@ifnextchar[\convTeXLength@i{\convTeXLength@i[cm]}}% [unit] +\def\convTeXLength@i[#1]{\@ifnextchar[{\convTeXLength@ii[#1]}{\convTeXLength@ii[#1][-1]}} +\def\convTeXLength@ii[#1][#2]#3{% + \conv@setlength\@tempdima{#3}% + \expandafter\convLen@iii\expandafter{\expandafter\rem@pt\the\@tempdima}{#1}{#2}} + +\def\convLen@iii#1#2#3{% #1 length; #2 unit; #3 decimals + \@ifnextchar[{\convLen@v{#1}{#2}{#3}}{\convLen@iv{#1}{#2}{#3}}} + +\def\convLen@iv#1#2#3{% + \@tempdima=1em \@tempdimb=1ex + \directlua{% + convList["em"]=\strip@pt\@tempdima; + convList["ex"]=\strip@pt\@tempdimb; + convList["mu"]=convList["em"]/18 + }% + \ifconv@Scientific + \luaexec{% + div0 = convList["#2"] + if (#3 < 0) then + tex.print(string.format("\%e",#1/div0)) + else + tex.print(string.format("\%#3e",#1/div0)) + end}% + \else + \luaexec{% + div0 = convList["#2"] + if (#3 < 0) then + tex.print(string.format(#1/div0)) + else + tex.print(string.format("\%.#3f",#1/div0)) + end}% + \fi + \text{\,#2}}% + +\def\convLen@v#1#2#3[#4]{% #1 length; #2 unit; #3 decimals; #4 orig unit + \@tempdima=1em \@tempdimb=1ex + \directlua{convList["em"]=\strip@pt\@tempdima; convList["ex"]=\strip@pt\@tempdimb; convList["mu"]=convList["em"]/18;}% + \ifconv@Scientific + \luaexec{% + divOrig = convList["#4"] + div0 = convList["#2"] + if (#3 < 0) then + tex.print(string.format("\%e",#1*divOrig/div0)) + else + tex.print(string.format("\%#3e",#1*divOrig/div0)) + end}% + \else + \luaexec{% + divOrig = convList["#4"] + div0 = convList["#2"] + if (#3 < 0) then + tex.print(string.format(#1*divOrig/div0)) + else + tex.print(string.format("\%.#3f",#1*divOrig/div0)) + end}% + \fi + \text{\,#2}}% + + +\newdimen\conv@unit \conv@unit 1cm +\def\conv@unit@off{\let\@conv@unit\ignorespaces\ignorespaces} +% +\def\conv@setlength#1#2{% + \let\@conv@unit\conv@unit + \afterassignment\conv@unit@off + #1 #2\@conv@unit% +} + + +\endinput + |