LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Philipp Stephani <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Wed, 17 Feb 2010 15:38:27 +0100
Content-Type:
text/plain
Parts/Attachments:
text/plain (68 lines)
Am 17.02.2010 um 14:12 schrieb Lars Hellström:

>> – e.g. with argument specifiers like "s" and "v" in xparse.
> 
> Not quite that compact, but the concept of "argument processors" was added to xparse in part to support this kind of thing.

I have read about them, but the manual says "xparse introduces the idea of an argument processor, which is applied to an argument after it has been grabbed by the underlying system but before it is passed to ⟨code⟩." so they can't be applied here – the catcode changes must be performed before the argument is grabbed. Once it is through the input processor, things like spaces and comments are inevitably lost. I thought of something like this:


\documentclass{minimal}

\usepackage{expl3}

\makeatletter
\ExplSyntaxOn
\msg_new:nnn { test } { not-outer } {syntax error \msg_line_context:}
\cs_new_protected_nopar:Npn \NewVerbatimCommand #1 #2 {
  \cs_new_protected_nopar:Npx #1 {
    \exp_not:n {
      \group_begin:
      \let\do\@makeother \dospecials
    }
    \exp_not:c { \cs_to_str:N #1 _aux_i:NwN }
  }
  \cs_new_protected_nopar:cpx { \cs_to_str:N #1 _aux_i:NwN } ##1 {
    \exp_not:N \cs_new_protected_nopar:Npn \exp_not:c { \cs_to_str:N #1 _aux_ii:wN } ####1 ##1 {
      \exp_not:n {
        \tl_set:Nn \l_test_tmpa_tl { ##1 }
        \tl_map_inline:Nn \l_test_tmpa_tl {
          % TODO: here we must find out whether the token is in fact a group
          \bool_if:nF {
            ( ! \token_if_cs_p:N ####1 ) &&
            ( \token_if_letter_p:N ####1 || \token_if_other_char_p:N ####1 )
          } {
            \msg_error:nn { test } { not-outer }
            \exp_args:NNno \tl_set_rescan:Nnn \l_test_tmpa_tl { } \l_test_tmpa_tl
            \tl_map_break:
          }
        }
        \exp_args:No
      }
      \exp_not:c { \cs_to_str:N #1 _aux_iii:n }
      \exp_not:n {
        \l_test_tmpa_tl
        \group_end:
      }
    }
    \exp_not:c { \cs_to_str:N #1 _aux_ii:wN }
  }
  \cs_new_protected_nopar:cpn { \cs_to_str:N #1 _aux_iii:n } ##1 {
    #2
  }
}
\ExplSyntaxOff
\makeatother

\NewVerbatimCommand\myverb{\quitvmode\texttt{#1}}

\begin{document}

\null

\myverb+ab  c d\ef#% gh +

\mbox{\myverb+ab  c d\ef gh +}

\end{document}

ATOM RSS1 RSS2