Hot answers tagged

55

The LaTeX3 coding language, expl3, uses : and _ as 'letters' in function and variable names. This allows use of expl3 code-level material in a document \cs_new:Npn .... % fails: command \cs followed by characters '_', 'n', 'e', 'w', etc. \ExplSyntaxOn \cs_new:Npn .... % works here: command name \cs_new:Npn The \ExplSyntaxOn command activates this, and also ...


44

Full example In the first implementation of the template ideas there has been a full example that tried to work through the underlying ideas. On can still find the documentation of template.dtx on the web, e.g., here. This is for a different implementation but the basic concepts haven't changed so it might be helpful still. Somehow during the ...


41

The history of that name (as I remember it at least) goes way back to a stroll in some town in the UK sometime in the last century, probably 1997 (may have been Nottingham, but I don't remember) with David Carlisle and Chris Rowley and perhaps a few others on which we discussed those ideas about boxes with handles and somehow somebody came up with "rather ...


38

Here is a flat LaTeX2e implementation. \documentclass{article} \usepackage{amsmath} \newcount{\numerator} \newcount{\denominator} \newcount{\gcd} % compute \gcd and returns reduced \numerator and \denominator \newcommand{\reduce}[2]% #1=numerator, #2=denominator {\numerator=#1\relax \denominator=#2\relax \loop \ifnum\numerator<\denominator \...


37

If you want to publish in academic journals, you need to be sensitive to what new TeX related goodies their setup can handle. For instance, I've had to regress from BibLaTeX to BibTeX because a journal couldn't handle it. Likewise, I'd expect that LuaTeX or ConTeXt might not fit well into the workflow of a journal. I'm sure there are people here who know ...


36

Currently, we don't have a Programming in LaTeX3 book, and even if we did there would be lots of gaps. So there is no 'complete' solution. However, there are some resources. First, I'd point to the introduction to LaTeX3 ideas which gives a broad-brush overview of the concepts. I have written a short series of blog posts on the topic: I've summarised the '...


36

I don't think syntax highlighting should be done purely in Tex for following reasons: Languages are complicated (context sensitive) and to proper highlight the syntax, you have to implement a full compiler front-end. As an example, here is some simple C++ code: struct foo; // foo is the name of a data type void f(foo param); // function f, taking a foo as ...


36

The function you mention has a name consisting of three parts: cs, set and eq. cs is the “module name”: the function deals with functions (for definitions and things alike); cs stands for “control sequence”, probably it's not the best name, but it's too late for changing it. set is the main action type; in this module there are basically three action types: ...


36

Underscores \csSetEq wouldn't work: for such basic, internal commands you need names that a normal user can't accidental overwrite. That's why internal LaTeX2e commands have @ and context uses ! and also underscores: \c_anch_sidebars_current \c!bottomoffset. expl3 couldn't use @ as it could to easily clash with existing commands and packages and from the ...


35

Update (2017-02-14) Thanks to the time spent on the answer below, and to some new features in WinEdt 10.2, now WinEdt 10.2 is really "LaTeX3-sensitive". WinEdt 10.2 incorporates the highlighting scheme in this answer (with many improvements) and features many other functionalities to support LaTeX3 (e.g. command completion for commands and ...


33

The degree to which something is 'stable enough' will depend on your requirements. I'll answer by taking this situation in roughly the order of stability as I see it. If you want 'will never change again', then plain TeX is probably your best bet. Knuth does still fix bugs periodically, but most things are now likely to be regarded as 'features' rather than ...


31

An expandable command is one which can be converted 'fully' into it's output inside a TeX \edef or \write (and a few other places). Thus for example \def\testa{\testb} \def\testb{\testc} \def\testc{d} \edef\teste{\testa} \show\teste will give > \teste=macro: ->d. i.e. all of the steps have been expanded, and we have just characters. For text, this ...


30

Although these issues were discussed earlier here are some pointers, from someone that has been using TeX/LaTeX since the middle 80s. The knowledge you build with TeX/LaTeX and friends is additive. What you have used as plain TeX commands, your \defs and similar can be used today with all of the above variants. Similarly for all the LaTeX commands and yes ...


30

\NewDocumentCommand is part of xparse, which is 'LaTeX3-in-2e' code. The team have marked this part as 'stable', meaning that we will maintain this code for use with LaTeX2e in an ongoing sense. As such, there is no danger of \NewDocumentCommand vanishing. Conceptually, \NewDocumentCommand is intended for 'package authors' to define commands, while \...


29

If you are not bound to expl3 (in which case you “just” need to implement the algorithm): \documentclass{scrartcl} \usepackage{xintgcd,xintfrac} \newcommand*\reducedfrac[2] {\begingroup \edef\gcd{\xintGCD{#1}{#2}}% \frac{\xintNum{\xintDiv{#1}{\gcd}}}{\xintNum{\xintDiv{#2}{\gcd}}}% \endgroup} \begin{document} \[ \frac{278922}{74088} = \...


29

An option using Lua+LaTeX. Made small improvement. Made a Lua function to be called as a LaTeX command, with the numerator and denominator passed as arguments, instead of hardcoding the values in as before. The command is \simplify{a}{b}: \documentclass{article} \usepackage{luacode} \usepackage{amsmath} %------------------------ \begin{luacode} ...


28

As I think the concept of "variant" in expl3 is one of the most fundamental concepts for LaTeX3 I like to expand a bit on the answer already given by Joseph. Naming convention The naming convention for commands in LaTeX3 (expl3) structures the command name into \module_description:arg-specifiers module identifies the (main) type of data the function ...


28

Limitations of l3regex On page 12 of the documentation, under "The following features of PCRE or Perl will definitely not be implemented": Recursion: this is a non-regular feature. Back-references: non-regular feature, this requires backtracking, which is prohibitively slow. So it doesn't look like you will be able to track matched/unmatched ...


28

Yes, you can, and pretty easily too. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\computesum}{mmm} {% pass control to an internal function \svend_compute_sum:nnn { #1 } { #2 } { #3 } } % a variable for storing the partial sums \fp_new:N \l_svend_partial_sum_fp \cs_new_protected:Npn \svend_compute_sum:nnn #1 #2 #3 { ...


27

For the record, here's my font-lock settings for Emacs with LaTeX3. To make use of these, I define a latex3-mode which is derived from the inbuild latex-mode. (Note: I don't use AucTeX, I use the simple TeX modes.) The idea of the font-locking is similar to Joseph's in that it adds more matches for highlighting. I've added a specials for core functions (...


26

The idea is to have a formalised key=value interface to setting a set of parameters on some part of the typographic layout. So if you look at article's table of contents for example the customisation options vary from setting some internal @ named macros \newcommand\@pnumwidth{1.55em} \newcommand\@tocrmarg{2.55em} \newcommand\@dotsep{4.5} To setting top ...


25

An expl3 implementation: \nonstopmode \input expl3-generic \relax \ExplSyntaxOn % -*- expl3 -*- \cs_new:Nn \svend_gcd:nn { \int_compare:nNnTF {#2} = { 0 } {#1} { \svend_gcd:ff {#2} { \int_mod:nn {#1} {#2} } } } \cs_generate_variant:Nn \svend_gcd:nn { ff } \int_new:N \l__svend_tmp_int \cs_new:Nn \svend_reduced:nn { \int_set:Nn \...


24

Update 2020-01-21 The newest latex-dev announces itself as LaTeX2e <2020-02-01> pre-release-3 (develop 2020-1-16 branch) The main changes are extensions to the NFSS (the New Font Selection Mechanism for LaTeX): Many modern fonts available these days offer additional font faces, e.g., small caps italics or a condensed font series, etc. To better ...


23

TeXworks uses a simple regex-based approach to syntax highlighting, with the information stored in the file syntax-patterns.txt inside the folder TeXworks/configuration, which lives in a system-dependent location. I have a set of patterns for working with .dtx (LaTeX documented source) files, which include highlighting for expl3 code: [LaTeX DTX] # ...


23

If you have \let\oldmacro\somemacro but your macro names are being passed (or generated) as names so you have {oldmacro} and {newmacro} then you can go \expandafter\let\csname oldmacro\expandafter\endcsname\csname newmacro\endcsname but this is not very clear and when embedded in some larger set of macros is easy to get wrong and introduce weird bugs. ...


22

In so far as the top level LaTeX3 code isn't written, I'm sure it will improve "freedom of package ordering", "freedom of speech" and generally move the world towards peace and harmony. To answer your implied comment about LaTeX2e (the main point of this answer:) Might it be possible, for example, to suppress option clash checks It is easy to suppress ...


22

The following produces the result you are looking for: \documentclass{article} \usepackage{expl3} \ExplSyntaxOn \tl_new:N \l_demo_tl \cs_new:Npn \demo #1 { \tl_set:Nn \l_demo_tl {#1} \regex_replace_all:nnN { \_(.*?)\_ } { \c{emph}\cB\{ \1 \cE\} } \l_demo_tl \tl_use:N \l_demo_tl } \ExplSyntaxOff \begin{document} \demo{This is a _test_ document.} ...


22

I believe it is good practice. There are hundreds of functions in the current LaTeX3 kernel that make a macro programmer's life easier. I wouldn't use such a dramatic indentation as you do and surely I'd use \NewDocumentCommand: \NewDocumentCommand{\tangentcount}{ m } { \int_case:nnn { #1 } { { 1 } { exactly ~ one } { 2 } { exactly ~ two } ...


22

To expand Joseph's answer about commands and values: Macros defined with \NewDocumentCommand are robust, they don't get expanded when e.g. moved to the .toc. This is a good thing for commands like \cite which should do something in the .toc but in general is not wanted for values which can change in a document and where you want to transport the current ...


22

KOMA-Script is a family of documentclasses (scrbook scrartcl scrreprt scrlettr2), which allow you to customize your documents more than the standard classes (book article report letter) do. LaTeX3 is right now mainly a new programming language which is not directly useful for creating documents. It is meant to be the new way to write packages and classes. ...


Only top voted, non community-wiki answers of a minimum length are eligible