GeneralSpecifying arguments with xparse

LaTeX specific issues not fitting into one of the other forums of this category.
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

Specifying arguments with xparse

Post by erwann »

I don't understand how to write a command with a v and e arguments:
v Reads an argument “verbatim”, between the following character and its next oc- currence, in a way similar to the argument of the LATEX 2ε command \verb. Thus a v-type argument is read between two matching tokens, which cannot be any of %, \, #, {, } or ␣. The verbatim argument can also be enclosed between braces, { and }. A command with a verbatim argument will not work when it appears within an argument of another function.
e An optional set of embellishments, each of which requires a value. If a key is not present, -NoValue- is returned. The returned data is a token list comprising one braced entry per key, ordered as for the key list in the argument specification. Given as e{⟨tokens⟩}. All ⟨tokens⟩ must be distinct. This is an experimental type.
E As for e but returns one or more ⟨defaults⟩ if values are not given: E{⟨tokens⟩}{⟨defaults⟩}. See Section 0.6 for more details.
Could someone kindly provide an example for each showing their relevance?

Also have an issue with R's default value:
r Reads a “required” delimited argument, where the delimiters are given as ⟨token1 ⟩ and ⟨token2 ⟩: r⟨token1 ⟩⟨token2 ⟩. If the opening ⟨token⟩ is missing, the default marker -NoValue- will be inserted after a suitable error.
R As for r, this is a “required” delimited argument but has a user-definable recovery ⟨default⟩, given as R⟨token1⟩⟨token2⟩{⟨default⟩}.
Specifically, I would have thought blah{Daniels} would work in the code below. What am I getting wrong?

Code: Select all

\documentclass[fontsize=12pt]{minimal}
\usepackage{xparse}

\NewDocumentCommand{\foo}{r<>m}{#1~#2}
\NewDocumentCommand{\baz}{r<]m}{#1~#2}
\NewDocumentCommand{\blah}{R<>{Jack} m}{#1~#2}

\begin{document}

\foo<Jack>{Daniels}

%\foo[Jack]{Daniels} % Failed to find arg starting with <

\baz<Jack]{Daniels}

\blah<Jack>{Daniels} 

%Bug?
\blah{Daniels} % Failed to find arg starting with <  

\end{document}
PS: I edited this code as the scope of my questions were initially too broad. I'll post again if necessary if this part is resolved.
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Specifying arguments with xparse

Post by cgnieder »

Code: Select all

\NewDocumentCommand{\blah}{R<>{Jack} m}{#1~#2}
defines a required (!) argument which of course means that an error message is given when the argument is missing. When LaTeX is compiled with interaction=nonstopmode (which is not unusual) the compilation doesn't stop at the error. This is where the default value comes in: it us used as if it had been given as required argument.

If you want an optional argument with unusual parentheses then use D (delimited):

Code: Select all

\NewDocumentCommand{\blah}{D<>{Jack} m}{#1~#2}
v arguments define commands like LaTeX's \verb:

Code: Select all

\documentclass{article}
\usepackage{xparse}
 
\NewDocumentCommand{\foo}{v}{\texttt{#1}}
 
\begin{document}
 
\foo|Jack&$|

\foo+Jack&$+

\end{document}
The e-type is easiest explained with an example:

Code: Select all

\documentclass{article}
\usepackage{xparse}
 
\NewDocumentCommand{\foo}{e{^_}}{foo (#1)(#2)}
\NewDocumentCommand{\FOO}{E{^_}{{X}{Y}}}{FOO (#1)(#2)}

\begin{document}
 
\foo

\foo_{one}^{two}

\FOO

\FOO_{one}^{two}

\end{document}
site moderator & package author
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

Specifying arguments with xparse

Post by erwann »

Thank you for these explanations. I would have thought the 'chars' in e{chars} or E{chars} would have been specified as '_^' rather than '^_' given the example that follows. Either way, it fails to compile.

PS: someone knows how to copy paste from the console in TeXShop? (I can't select text within)
Attachments
Screen Shot 2018-02-23 at 5.19.16 PM.png
Screen Shot 2018-02-23 at 5.19.16 PM.png (18.15 KiB) Viewed 12769 times
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Specifying arguments with xparse

Post by Johannes_B »

Simply open the log file, better to upload the file after you added \listfiles at the very top.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

Specifying arguments with xparse

Post by erwann »

Here's the log
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Specifying arguments with xparse

Post by Stefan Kottwitz »

Please upload .log files here, as attachment. Some external upload site has advertisements and who knows about their content or even malware ( I don't know this expirebox.com).

That .log is so short that it could even be posted as code:

Code: Select all

This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex 2018.2.5)  24 FEB 2018 15:03
entering extended mode
 restricted \write18 enabled.
 file:line:error style messages enabled.
 %&-line parsing enabled.
**argE.tex
(./argE.tex
LaTeX2e <2017/01/01> patch level 3
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/minimal.cls
Document Class: minimal 2001/05/25 Standard LaTeX minimal class
) (/usr/local/texlive/2016/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/expl3.sty
Package: expl3 2017/04/01 L3 programming layer (loader) 

(/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/expl3-code.tex
Package: expl3 2017/04/01 L3 programming layer (code)
\c_max_int=\count79
\l_tmpa_int=\count80
\l_tmpb_int=\count81
\g_tmpa_int=\count82
\g_tmpb_int=\count83
\g__prg_map_int=\count84
\c_log_iow=\count85
\l_iow_line_count_int=\count86
\l__iow_line_target_int=\count87
\l__iow_one_indent_int=\count88
\l__iow_indent_int=\count89
\c_zero_dim=\dimen102
\c_max_dim=\dimen103
\l_tmpa_dim=\dimen104
\l_tmpb_dim=\dimen105
\g_tmpa_dim=\dimen106
\g_tmpb_dim=\dimen107
\c_zero_skip=\skip41
\c_max_skip=\skip42
\l_tmpa_skip=\skip43
\l_tmpb_skip=\skip44
\g_tmpa_skip=\skip45
\g_tmpb_skip=\skip46
\c_zero_muskip=\muskip10
\c_max_muskip=\muskip11
\l_tmpa_muskip=\muskip12
\l_tmpb_muskip=\muskip13
\g_tmpa_muskip=\muskip14
\g_tmpb_muskip=\muskip15
\l_keys_choice_int=\count90
\c__fp_leading_shift_int=\count91
\c__fp_middle_shift_int=\count92
\c__fp_trailing_shift_int=\count93
\c__fp_big_leading_shift_int=\count94
\c__fp_big_middle_shift_int=\count95
\c__fp_big_trailing_shift_int=\count96
\c__fp_Bigg_leading_shift_int=\count97
\c__fp_Bigg_middle_shift_int=\count98
\c__fp_Bigg_trailing_shift_int=\count99
\c__fp_rand_size_int=\count100
\c__fp_rand_four_int=\count101
\c__fp_rand_eight_int=\count102
\l__sort_length_int=\count103
\l__sort_min_int=\count104
\l__sort_top_int=\count105
\l__sort_max_int=\count106
\l__sort_true_max_int=\count107
\l__sort_block_int=\count108
\l__sort_begin_int=\count109
\l__sort_end_int=\count110
\l__sort_A_int=\count111
\l__sort_B_int=\count112
\l__sort_C_int=\count113
\c_empty_box=\box26
\l_tmpa_box=\box27
\l_tmpb_box=\box28
\g_tmpa_box=\box29
\g_tmpb_box=\box30
\l__coffin_internal_box=\box31
\l__coffin_internal_dim=\dimen108
\l__coffin_offset_x_dim=\dimen109
\l__coffin_offset_y_dim=\dimen110
\l__coffin_x_dim=\dimen111
\l__coffin_y_dim=\dimen112
\l__coffin_x_prime_dim=\dimen113
\l__coffin_y_prime_dim=\dimen114
\c_empty_coffin=\box32
\l__coffin_aligned_coffin=\box33
\l__coffin_aligned_internal_coffin=\box34
\l_tmpa_coffin=\box35
\l_tmpb_coffin=\box36
\l__coffin_display_coffin=\box37
\l__coffin_display_coord_coffin=\box38
\l__coffin_display_pole_coffin=\box39
\l__coffin_display_offset_dim=\dimen115
\l__coffin_display_x_dim=\dimen116
\l__coffin_display_y_dim=\dimen117
\l__box_top_dim=\dimen118
\l__box_bottom_dim=\dimen119
\l__box_left_dim=\dimen120
\l__box_right_dim=\dimen121
\l__box_top_new_dim=\dimen122
\l__box_bottom_new_dim=\dimen123
\l__box_left_new_dim=\dimen124
\l__box_right_new_dim=\dimen125
\l__box_internal_box=\box40
\l__coffin_bounding_shift_dim=\dimen126
\l__coffin_left_corner_dim=\dimen127
\l__coffin_right_corner_dim=\dimen128
\l__coffin_bottom_corner_dim=\dimen129
\l__coffin_top_corner_dim=\dimen130
\l__coffin_scaled_total_height_dim=\dimen131
\l__coffin_scaled_width_dim=\dimen132
)
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/l3pdfmode.def
File: l3pdfmode.def 2017/03/18 v L3 Experimental driver: PDF mode
\l__driver_color_stack_int=\count114
\l__driver_tmp_box=\box41
))
Package: xparse 2017/04/01 L3 Experimental document command parser
\l__xparse_current_arg_int=\count115
\g__xparse_grabber_int=\count116
\l__xparse_m_args_int=\count117
\l__xparse_mandatory_args_int=\count118
\l__xparse_v_nesting_int=\count119
)
.................................................
. LaTeX info: "xparse/define-command"
. 
. Defining command \foo with sig. 'e{^_}' on line 5.
......
Anyway, better upload here than to another upload or file sharing site, thanks.

Stefan
LaTeX.org admin
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

Specifying arguments with xparse

Post by erwann »

Will do.
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Specifying arguments with xparse

Post by Stefan Kottwitz »

Clemens' example code is compilable without error. Your .log file is probably not complete. At the end, it's just an informational message.
Can you get it complete? What is your code (MWE) and the error?

Stefan
LaTeX.org admin
erwann
Posts: 75
Joined: Thu Aug 25, 2016 2:24 am

Specifying arguments with xparse

Post by erwann »

Code copy pasted frm example posted, log comes from TeXShop>file>Show log. Will try again with texlive 2017 upgrade. For now,

Code: Select all

This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex 2018.2.5)  24 FEB 2018 18:25
entering extended mode
 restricted \write18 enabled.
 file:line:error style messages enabled.
 %&-line parsing enabled.
**argE.tex
(./argE.tex
LaTeX2e <2017/01/01> patch level 3
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/size10.clo
File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
)
\c@part=\count79
\c@section=\count80
\c@subsection=\count81
\c@subsubsection=\count82
\c@paragraph=\count83
\c@subparagraph=\count84
\c@figure=\count85
\c@table=\count86
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
)
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/expl3.sty
Package: expl3 2017/04/01 L3 programming layer (loader) 

(/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/expl3-code.tex
Package: expl3 2017/04/01 L3 programming layer (code)
\c_max_int=\count87
\l_tmpa_int=\count88
\l_tmpb_int=\count89
\g_tmpa_int=\count90
\g_tmpb_int=\count91
\g__prg_map_int=\count92
\c_log_iow=\count93
\l_iow_line_count_int=\count94
\l__iow_line_target_int=\count95
\l__iow_one_indent_int=\count96
\l__iow_indent_int=\count97
\c_zero_dim=\dimen103
\c_max_dim=\dimen104
\l_tmpa_dim=\dimen105
\l_tmpb_dim=\dimen106
\g_tmpa_dim=\dimen107
\g_tmpb_dim=\dimen108
\c_zero_skip=\skip43
\c_max_skip=\skip44
\l_tmpa_skip=\skip45
\l_tmpb_skip=\skip46
\g_tmpa_skip=\skip47
\g_tmpb_skip=\skip48
\c_zero_muskip=\muskip10
\c_max_muskip=\muskip11
\l_tmpa_muskip=\muskip12
\l_tmpb_muskip=\muskip13
\g_tmpa_muskip=\muskip14
\g_tmpb_muskip=\muskip15
\l_keys_choice_int=\count98
\c__fp_leading_shift_int=\count99
\c__fp_middle_shift_int=\count100
\c__fp_trailing_shift_int=\count101
\c__fp_big_leading_shift_int=\count102
\c__fp_big_middle_shift_int=\count103
\c__fp_big_trailing_shift_int=\count104
\c__fp_Bigg_leading_shift_int=\count105
\c__fp_Bigg_middle_shift_int=\count106
\c__fp_Bigg_trailing_shift_int=\count107
\c__fp_rand_size_int=\count108
\c__fp_rand_four_int=\count109
\c__fp_rand_eight_int=\count110
\l__sort_length_int=\count111
\l__sort_min_int=\count112
\l__sort_top_int=\count113
\l__sort_max_int=\count114
\l__sort_true_max_int=\count115
\l__sort_block_int=\count116
\l__sort_begin_int=\count117
\l__sort_end_int=\count118
\l__sort_A_int=\count119
\l__sort_B_int=\count120
\l__sort_C_int=\count121
\c_empty_box=\box26
\l_tmpa_box=\box27
\l_tmpb_box=\box28
\g_tmpa_box=\box29
\g_tmpb_box=\box30
\l__coffin_internal_box=\box31
\l__coffin_internal_dim=\dimen109
\l__coffin_offset_x_dim=\dimen110
\l__coffin_offset_y_dim=\dimen111
\l__coffin_x_dim=\dimen112
\l__coffin_y_dim=\dimen113
\l__coffin_x_prime_dim=\dimen114
\l__coffin_y_prime_dim=\dimen115
\c_empty_coffin=\box32
\l__coffin_aligned_coffin=\box33
\l__coffin_aligned_internal_coffin=\box34
\l_tmpa_coffin=\box35
\l_tmpb_coffin=\box36
\l__coffin_display_coffin=\box37
\l__coffin_display_coord_coffin=\box38
\l__coffin_display_pole_coffin=\box39
\l__coffin_display_offset_dim=\dimen116
\l__coffin_display_x_dim=\dimen117
\l__coffin_display_y_dim=\dimen118
\l__box_top_dim=\dimen119
\l__box_bottom_dim=\dimen120
\l__box_left_dim=\dimen121
\l__box_right_dim=\dimen122
\l__box_top_new_dim=\dimen123
\l__box_bottom_new_dim=\dimen124
\l__box_left_new_dim=\dimen125
\l__box_right_new_dim=\dimen126
\l__box_internal_box=\box40
\l__coffin_bounding_shift_dim=\dimen127
\l__coffin_left_corner_dim=\dimen128
\l__coffin_right_corner_dim=\dimen129
\l__coffin_bottom_corner_dim=\dimen130
\l__coffin_top_corner_dim=\dimen131
\l__coffin_scaled_total_height_dim=\dimen132
\l__coffin_scaled_width_dim=\dimen133
)
(/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/l3pdfmode.def
File: l3pdfmode.def 2017/03/18 v L3 Experimental driver: PDF mode
\l__driver_color_stack_int=\count122
\l__driver_tmp_box=\box41
))
Packag
Attachments
Screen Shot 2018-02-24 at 6.26.01 PM.png
Screen Shot 2018-02-24 at 6.26.01 PM.png (64.72 KiB) Viewed 12654 times
x_86 / Linux Mint 18.3 / texlive 2015.20160320-1ubuntu0.1 / TeXworks 0.5r1361 (Debian)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Specifying arguments with xparse

Post by Stefan Kottwitz »

There's a file with the extension .log in your document's folder, you can attach that, it's easier than copy and paste from a TeXshop window.

Stefan
LaTeX.org admin
Post Reply