Debian Codegraph @

texmf-dist/doc/latex/l3kernel/l3news08.tex

raw
1 % Copyright 2012 The LaTeX3 Project
2 \documentclass{ltnews}
3
4 \PassOptionsToPackage{colorlinks}{hyperref}
5
6 \usepackage{metalogo,ragged2e}
7
8 \AtBeginDocument{
9 \renewcommand{\LaTeXNews}{\LaTeX3~News}
10 \RaggedRight
11 }
12
13 \usepackage{expl3,siunitx,catchfile}
14 \usepackage{hologo}
15 \usepackage{verbatim}% avoid ltnews' "special" verbatim processing
16
17 \publicationmonth{July}
18 \publicationyear{2012}
19 \publicationissue{8}
20
21 \def\DTX{\texttt{.dtx}}
22 \def\STY{\texttt{.sty}}
23
24 \ExplSyntaxOn
25 \NewDocumentCommand { \calcnum } { m }
26 { \num { \fp_to_scientific:n {#1} } }
27 \ExplSyntaxOff
28
29 \begin{document}
30 \maketitle
31
32 \raisefirstsection
33 \section{Extended floating point support}
34
35 Bruno Le Floch has been re-writing the floating point module to function in an `expandable' manner. This allows floating point calculations to be computed far more flexibly and efficiently than before.
36 The expandable nature of the new code allows its use inside operations such as writing to external files, for which previously any such calculations would have to be pre-calculated before any of the writing operations began.
37
38 Bruno's work on the floating point module has been officially released into the main \textsc{svn} repository for \texttt{l3kernel}; \TeX\ Live 2012 will contain the `old' code for stability while this year is spent testing the new code in production environments and ironing out any wrinkles.
39
40 Here's a neat example as suggested in the documentation, which produces `\calcnum { round ( 200 pi * sin ( 2.3 ^ 5 ) , 2 ) }':
41
42 \begin{verbatim}
43 \usepackage{xparse, siunitx}
44 \ExplSyntaxOn
45 \NewDocumentCommand { \calcnum } { m }
46 { \num { \fp_to_scientific:n {#1} } }
47 \ExplSyntaxOff
48
49 \calcnum {
50 round ( 200 pi * sin ( 2.3 ^ 5 ) , 2 )
51 }
52 \end{verbatim}
53
54 This feature is invaluable for simple (and not-so-simple) calculations in document and package authoring, and has been lacking a robust solution for many years.
55 While \hologo{LuaLaTeX} can perform similar tasks within its Lua environment, the floating point support is written using the \texttt{expl3} programming language only, and is thus available in \hologo{pdfLaTeX} and \hologo{XeLaTeX} as well.
56
57 \section{Regular expressions in \TeX}
58
59 As if expandable floating point support wasn't enough, Bruno has also written a complete regular expression engine in \texttt{expl3} as well.
60 % [Ed: Consider my mind blown.]
61 Many reading this will be familiar with the quote attributed to Jamie Zawinski:
62 \begin{quote}\itshape
63 Some people, when confronted with a problem, think
64 ``I know, I'll use regular expressions.''
65 Now they have two problems.
66 \end{quote}
67 And as humorous as the saying is, it's still fair to say that regular expressions are a great tool for manipulating streams of text.
68 We desperately hope that people will \emph{not} start using the regex code to do things like parse \textsc{xml} documents; however, for general search--replace duties, there's never been anything like \texttt{l3regex} for the \LaTeX\ world.
69 As a trivial example, there are
70 \CatchFileDef\thisfile{\jobname.tex}{}%
71 \ExplSyntaxOn
72 \exp_args:Nno \regex_count:nnN { \b (?i) W e \b } {\thisfile} \l_tmpa_int
73 \int_use:N \l_tmpa_int
74 \ExplSyntaxOff
75 ~instances of the word `We' or `we' in this document (including those two).
76 This value is counted automatically in two lines of code.
77
78 And again, it is available for \hologo{pdfLaTeX} and \hologo{XeLaTeX} users as well as \hologo{LuaLaTeX} ones; it also bears noting that this provides an easy solution for applying regular expression processing to \LaTeX\ documents and text data even on the Windows operating system that does not have native support for such things.
79
80
81 \section{Separating internal and external code}
82
83 \LaTeX\ packages are written by a wide range of package authors and consist of code and commands for various purposes.
84 Some of these commands will be intended for use by document authors (such as \verb|\pbox| from the \textsf{pbox} package); others are intended for use by other package writers (such as \verb|\@ifmtarg| from the \textsf{ifmtarg} package).
85
86 However, a large portion of them are internal, i.e., are intended to
87 be used only within the package or within the \LaTeX{} kernel and
88 should not be used elsewhere. For example, \verb|\@float| is the
89 \LaTeX{} kernel interface for floats to be used in class files, but
90 the actual work is done by a command called \verb|\@xfloat| which
91 should not be used directly. Unfortunately the \LaTeXe{} language
92 makes no clear distinction between the two, so it is tempting for
93 programmers to directly call the latter to save some ``unnecessary''
94 parsing activity.
95
96 The downside of this is that the ``internal'' commands suddenly act as
97 interfaces and a reimplementation or fix in any of them would then
98 break add-on packages as they rely on internal behavior. Over the
99 course of the last twenty years probably 80\% of such ``internal''
100 commands have found their way into one or another package. The
101 consequences of this is that nowadays it is next to impossible to
102 change anything in the \LaTeXe{} kernel (even if it is clearly just an
103 internal command) without breaking something.
104
105
106 In \LaTeX3 we hope to improve this situation drastically by
107 clearly separating public interfaces (that extension packages can use
108 and rely on) and private functions and variables (that should not
109 appear outside of their module). There is (nearly) no way to enforce
110 this without severe computing overhead, so we implement it only
111 through a naming convention, and some support mechanisms. However, we
112 think that this naming convention is easy to understand and to follow,
113 so that we are confident that this will be adopted and provides the
114 desired results.
115
116 \subsection{Naming convention for internals}
117
118 We've been throwing around some ideas for this for a number of years but nothing quite fit; the issue comes down to the fact that \TeX\ does not have a `name-spacing' mechanism so any internal command needs to have a specific prefix to avoid clashing with other packages' commands.
119 The prefix we have finally decided on for \textsf{expl3} code is a double underscore, such that functions like \verb|\seq_count:N| are intended for external use and \verb|\__seq_item:n| is an internal command that should not be used or relied upon by others.
120
121 All this is well and good, but it can be inconvenient to type long prefixes such as \verb|\__seq_| before all command names, especially in a package for which nearly \emph{all} package functions are internal.
122
123 We therefore also extended \textsf{DocStrip} slightly by adding a `shorthand' for internal package prefixes.
124 Commands and variables in \DTX\ code may now contain \texttt{@@} which is expanded to the function prefix when the \STY\ file is extracted.
125 As an example, writing
126 \begin{verbatim}
127 %<@@=seq>
128 \cs_new:Npn \@@_item:n
129 ...
130 \end{verbatim}
131 is equivalent to
132 \begin{verbatim}
133 \cs_new:Npn \__seq_item:n
134 ...
135 \end{verbatim}
136 There are clear advantages to this syntax.
137 Function names are shorter and therefore easier to type, and code can still be prototyped using the \texttt{@@} syntax
138 (e.g., pasting code between a \DTX\ file and a regular \texttt{.tex} document).
139 Most importantly, it is explicitly clear from the code source which commands are intended to be used externally and which should be avoided.
140
141 We hope that this syntax will prove popular; in our initial experiments we think it works very well. In fact we found a good number of smaller errors when being forced to think about what is internal and what is an external function.
142
143 \section{Continual revolution---the `small bang'}
144
145 In addition to the major additions introduced above, Frank Mittelbach has been examining \texttt{expl3} with a fresh eye to resolve any outstanding issues in the consistency or logic of the names of functions.
146
147 We are very mindful of the fact that for people to find \texttt{expl3} a useful tool, it must have a stable interface.
148 This said, there are still some musty corners that we can show where people simply haven't been using certain functions.
149 In select cases, we're re-assessing whether all of the (sometimes esoteric) odds and ends that have been added to \texttt{expl3} really belong; in other cases, it's now clear that some naming or behaviour choices weren't correct the first time around.
150
151 To address this tarnish, we're carefully making some minor changes to parts of the \texttt{expl3} interface and we'd like to allay any fears that \texttt{expl3} isn't stable.
152 The \texttt{expl3} language now offers a wide range of functions plus their variants, and we're talking about changing but a very small percentage of these, and not common ones at that.
153 We don't want it to become a mess, so we think it's better to tidy things up as we go.
154 Follow the \texttt{LaTeX-L} mailing list for such details as they arise.
155
156 \end{document}
157
158
159 dropped/replaced:
160
161 The \LaTeX3 codebases ranges between these two extremes; the packages
162 in \texttt{l3packages} are largely the former while the modules
163 composing \textsf{expl3} are largely the latter type. In both cases,
164 the `external' commands (whether for document author or package
165 writer) are usually defined in terms of other internal package
166 commands that should not be used by anyone else, but often when
167 reading the internal package code it's not always clear which is
168 which.
169
170 For \LaTeX3 we are experimenting with an extension to the \textsf{DocStrip} mechanism to provide a clear distinction between internal and external package commands.