New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document catcodes for xparse's "verbatim" argument type, document how to reproduce \verb #756
Comments
What you are seeing is the \documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xparse}
\makeatletter
% \NewDocumentCommand {\myverb} { v } { \showtokens{#1} }
\NewDocumentCommand {\myverb} { v } {#1}
\begin{document}
\makeatletter
\ttfamily \@noligs
-- and \verb|--all|
- and \myverb{-all}
-- and \myverb{--all}
--- and \myverb{---all}
\end{document} |
but v in xparse is supposed to be verbatim (is it not ?) and in LaTeX that means typewriter with ligatures suppressed so v should do that too in my opinion. |
It just grabs verbatim (verbatim here being some equivalent of Perhaps some way to allow the command to add its own catcode settings, like: \NewDocumentCommand {\myverb} { v{\@noligs} } {#1} |
@FrankMittelbach I agree with PhelypeOleinik that “verbatim” means “grab whatever user has written verbatim”. The |
But isn't |
@dbitouze — not really. \verb has two parts to it — argument grabbing and formatting. The “v” setting in \NewDocumentCommand only does the former.
@phelype — unless I’m missing something, doesn’t your suggestion do no more than this?:
\NewDocumentCommand {\myverb} { v } { {\@noligs #1} }
In that case I don’t think it is necessary. So back to @dbitouze, the way to replicate \verb is something like:
\makeatletter
\NewDocumentCommand {\myverb} { v } { {\@noligs\ttfamily #1} }
\makeatother
|
On Thu, 25 Jun 2020 at 08:22, Denis Bitouzé ***@***.***> wrote:
But isn't \NewDocumentCommand {\myverb} { v } {#1}\myverb{--all} supposed
to behave as \verb|--all|?
—
Not exactly, as `v` is just about parsing the argument, and that is read
verbatim, \verb also typesets the content in a non standard monospace font
setup that suppresses ligatures.
so rather than just `#1` to typeset the argument in the current font you'd
need to do
\verbatim@font\@noligs
\language\l@nohyphenation
except that \@noligs requires
\def\verbatim@nolig@list{\do\`\do\<\do\>\do\,\do\'\do\-}
to be active so we could consider either making v set those as active. or
providing a wrapper around scantokens that arranges that \@noligs can work
here
… You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#756 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJVYAVLBB4ABB3DD5TETRDRYL3MPANCNFSM4OHMH74A>
.
|
@dbitouze no, the similarity is only in the way the argument can be delimited: you can use \myverb!abc!. The result is documented as
The argument parser only reads an argument, it doesn't typeset it. And it would make no sense to add font commands or other commands to it or even to preprocess it to apply
|
@wspr Kind of, but no: |
Thanks @phelype — it’s been a while since I looked inside that macro :)
In that case I like the idea of the setup argument… even if in this instance other approaches can also work to disable the ligatures.
|
We don't have optional data in the arg spec, so it would need a new letter ( |
Or a breaking change to |
I would rather vote for |
Can't we add one? Or perhaps, since we have |
Imho if the catcodes should be customizable for the v-type it would make sense to use the cctab code, and not some arbitrary command like |
@u-fischer So I better get that PR for |
Currently, I've no idea on how |
My point was that semantically |
I'll get the |
@dbitouze A catcode table is a way of having a 'fixed' set of catcode for all chars(*). It means you get a one-token interface for the changes, so '
|
@josephwright (off topic) It seems to me that you wanted to add a footnote but Markdown didn’t know that. |
Suppressing a known set of ligatures during output can also be done by using |
@Skillmon Good point: one could take the verbatim material and replace tokens. As everything is strictly verbatim, that's probably an easier approach than worrying about catcode setup. |
Regardless of the outcome of this discussion, it will be useful to document in
xparse.pdf how to reproduce the behaviour of \verb using \NewDocumentCommand.
|
@josephwright depending on the number of tokens to be replaced the performance will be a lot worse with the |
Also, how will you know which characters (in a very large font) need replacing? Further: what does typesetting ‘verbatim with a monospaced font’ mean for many scripts (non-European)? |
@car222222 in a very large font you got the font features as the only reasonable way to suppress them all, LaTeX can't know about all ligatures possible in a font. But at least the characters supported LaTeX2e could be covered easily (it's just a Further: AFAIK there are double spaced symbols in some monospaced fonts for some non-European scripts. |
I would suggest just wrapping every character in an hbox. It seems to work
reasonably well, but I didn't test extensively.
\RequirePackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\myverb}{v}{\texttt{\str_map_function:nN{#1}\hbox:n}}
\ExplSyntaxOff
\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}
\verb|a--b ---c ``<''|
\myverb|a--b ---c ``<''|
\end{document}
|
Try with |
Ok, second attempt (the
|
But not everyone. E.g. the quote here is not active:
gives
|
@u-fischer but which of these two outputs does one want in the ‘verbatim text’? The Non-active " case looks to me like what LaTeX used to mean by ‘verbatim’. But maybe some people expect the output to be, for example, ä which does not look much like ‘verbatim’ to other people. As I have written so many times: what does ‘verbatim’ mean outside printable 7-bit ASCII? |
@car222222 my example is about input not output. I'm not outputting anything, only analysing how the argument grabed by xparse looks like. From the documentation I expected the argument to let active chars as they are and convert all other tokens to catcode 12, and spaces to catcode 10. But as some tests show my expectation was wrong: active chars setup with babel are converted to catcode 12 too as the argument parser contains a \dospecial. |
One other question: Should this |
@u-fischer Input/output ?? But you answered my implied question. You want to keep the active “ but I think that verbatim should produce the non-active “ so that no ä glyph can be output. |
When I say “I think” I mean that this is what I would expect to follow from the original (40 years ago) concept of ‘verbatim’ in TeX/LaTeX. Maybe that concept+definitions needs to be changed, but to what exactly? |
Or as @RuixiZhang42 put it: how verbatim is 21st Century verbatim ? |
Interestingly \verb*|Y Z| (with two consecutive tabs) gives a single space
because \verb changes the catcode of space but not of tab.
I agree v-type (and "+v" too) argument is not well-defined right now. Would the
following make sense, using a catcode table?
- Give catcode 13 (active) to spaces and a few others (`\^^M for instance?).
- Give catcode 12 (other) to all other bytes 0-127 (in pdfTeX), 0-255 (in XeTeX,
upTeX, pTeX), or 0-1114111 (LuaTeX).
- In pdfTeX, give catcode 13 (active) to bytes 128-255.
Maybe it is better to keep some stuff as catcode 11 (letters)?
|
No I didn't say that. I only wrote that I expected this to happen after reading the documentation. This only implies that the documentation needs improving.
You can get |
@u-fischer You can get "a as output also with an active " Sure, but I do not know whether ‘verbatim mode’ should need such customisation? Maybe it should? Back to the question: what does ‘verbatim’ mean, both for reading an input token list and also for output (including what font, with what ligatures, kerning, other font features, etc.,etc.). Maybe something like this (for input of printable ASCII only): The environment must be customised to deal with the output (text representation) of any 7-bit ACSII character that might by the above process turn out to be out to be internally a catcode 13 token. [Quite a bit different from the original, but still covering only ASCII input, like the original.] |
@blefloch wrote: In pdfTeX, give catcode 13 (active) to bytes 128-255. Would you do this even if inputenc is not being used? What definition would you give them? I am unsure if anyone has thought much about utf-8 inputenc input to verbatim mode. Will this be supported, and what does it mean? |
It is supported, at least for T1 encoding. For greek or similar you would have to redefine \verbatim@font:
|
Possible suggestions for what the verbatim argument should do. I tend towards option 1, but I may be missing some aspects.
|
AFAICS, the document details of |
@dbitouze That commit is still in the head branch of open PR latex3/latex2e#1087. |
When
fontenc
is loaded with itsT1
option,\NewDocumentCommand
with verbatim argument gobbles the first-
if its content contains a--
(irrespective of the delimiters used):The text was updated successfully, but these errors were encountered: