16

The following code works as I would like it to: Given the state of the boolean, certain content is to be printed or not. If it's not printed, then I run the risk of creating extraneous whitespace. So, I use \ignorespaces to avoid this.

\documentclass{article} \usepackage{xparse} \ExplSyntaxOn \bool_new:N \g__ace_show_content_bool \bool_gset_true:N \g__ace_show_content_bool \NewDocumentCommand{\mycommand}{ m } { \bool_if:NTF \g__ace_show_content_bool { #1 } { \ignorespaces } } \NewDocumentCommand{\togglestate}{ } { \bool_if:NTF \g__ace_show_content_bool { \bool_gset_false:N \g__ace_show_content_bool } { \bool_gset_true:N \g__ace_show_content_bool } } \ExplSyntaxOff \pagestyle{empty} \begin{document} \textbf{Line 1:} Testing \mycommand{This} \mycommand{is} \mycommand{my} \mycommand{trial} \mycommand{run.} Testing \togglestate \textbf{Line 2:} Testing \mycommand{This} \mycommand{is} \mycommand{my} \mycommand{trial} \mycommand{run.} Testing \togglestate \textbf{Line 3:} Testing \mycommand{This} \mycommand{is} \mycommand{my} \mycommand{trial} \mycommand{run.} Testing \end{document} 

It seems that LaTeX3 already implements a large portion of what plain TeX does. So, it seems to me that plain TeX code like \ignorespaces doesn't really belong in a LaTeX3 context. But I can't find equivalents of \unskip and \ignorespaces in the LaTeX3 documentation.

Am I missing something? Is there another work-around? Or has this not been implemented yet?

3
  • 2
    \unskip and \ignorespaces belong to the realm of typesetting and current expl3 code doesn't treat it. There's nothing bad in using them, if you prefer not using \tex_unskip:D or \tex_ignorespaces:D. Commented Feb 22, 2013 at 15:42
  • Gotcha. I thought commands terminated in :D were verboten except for kernal development purposes. Commented Feb 22, 2013 at 15:45
  • @egreg I'm a fairly strong advocate for keeping :D commands verboten, see answer below. Commented Feb 23, 2013 at 12:39

1 Answer 1

13

Neither \unskip nor \ignorespaces are plain TeX commands, they are in fact TeX primitives and as such exist in plain TeX and LaTeX2e.

The renaming and standardization approach of expl3 has mapped them therefore to the names \tex_unskip:D and \tex_ignorespaces:D. And yes, :D commands are meant not to be used outside the kernel or core packages. The idea is that anything for programmers is provided on a higher level of abstraction. E.g., \tex_relax:D (the primitive \relax) is provided as \scan_stop: for normal programming tasks. And some :D commands are not provided at all directly because higher level concepts are better and sufficient.

Having said that, there are also areas in which the modules for expl3 are not at all finished or even started and the area of "typesetting text" is one of them. Dealing with glue and spaces in lists is one of the tasks that such a module would need to finally take care of.

So the question is how to deal with this:

  1. either you use the expl3 :D names for now
  2. or you use the TeX primitive names for now
  3. or you invent your own names, via \cs_set_eq:NN

Neither is perfect, but I would vote against 1. and suggest you always obey the don't use status of :D names and do not use them in real code.

The cleanest solution is perhaps to use 3. and have all such commands that you feel are necessary but not yet covered in a single place near the top of your code. This way once modules, say for "typesetting" and maniulating horizontal lists finally appear you know what parts to revisit.

4
  • Why not just close the {}} in the OP example? Is convention some higher principle than programmer convenience? And how would one define the \cs_set_eq:NN using the primitive \ignorespaces? I am afraid I am missing something here. I would appreciate it if you could expand with some code regarding 3). Commented Feb 23, 2013 at 18:26
  • @YiannisLazarides sorry, don't understand your first part of the comment. Mail me off-line to explain please. Close what? My point 3 simply means provide expl3 names if you don't want to use TeX primitive old names in your code, e.g., \cs_set:NN \scan_ignore_spaces: \tex_ignorespaces:D or something like that. Commented Feb 23, 2013 at 18:40
  • @YiannisLazarides the OP needs \ignorespaces or \unskip in the false branch to drop one of the space on either side of \mycommand to avoid getting 2 spaces in a row when the command doesn't produce any output. Commented Feb 24, 2013 at 8:41
  • @FrankMittelbach The advantage of 1 or 3 are that it is easy to find all places in one's code where shortcuts were taken: search for :D. For that reason, I never use the primitive TeX names. I guess 3 is best. Also, I wouldn't advise to define \scan_ignore_spaces:, rather \mypkg_ignore_spaces:. Commented Feb 24, 2013 at 11:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.