Avoid passing an empty optional argument an environment with verbatim content? Announcing the...

How to make an animal which can only breed for a certain number of generations?

When speaking, how do you change your mind mid-sentence?

Meaning of this sentence, confused by まで

Does traveling In The United States require a passport or can I use my green card if not a US citizen?

Like totally amazing interchangeable sister outfit accessory swapping or whatever

Why is one lightbulb in a string illuminated?

What could prevent concentrated local exploration?

Assertions In A Mock Callout Test

Coin Game with infinite paradox

Why doesn't the university give past final exams' answers?

What is the evidence that custom checks in Northern Ireland are going to result in violence?

Knights and Knaves question

If gravity precedes the formation of a solar system, where did the mass come from that caused the gravity?

Can I ask an author to send me his ebook?

How to mute a string and play another at the same time

A journey... into the MIND

Protagonist's race is hidden - should I reveal it?

Unix AIX passing variable and arguments to expect and spawn

Is the Mordenkainen's Sword spell underpowered?

Raising a bilingual kid. When should we introduce the majority language?

/bin/ls sorts differently than just ls

What's the connection between Mr. Nancy and fried chicken?

Can gravitational waves pass through a black hole?

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?



Avoid passing an empty optional argument an environment with verbatim content?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How to pass an optional argument to an environment with verbatim content?Emulating @ifnextchar in expl3xparse with underscore and optional argumentxparse command with just optional argument failsThree-way optional argument in xparsenewcommand with optional argumentHow to manipulate items of a SplitList while processing?Environment with argument and optional argumentEmpty optional argument or Not giving optional argument at all?Environment with comma separated optional argumentsHow to expand a macro (or a copy) to save in a list at end of environment in xparse (expl3)?xparse: forward empty optional argument












0















this query is related to How to pass an optional argument to an environment with verbatim content? (whose solution did not work in my case) and with Emulating @ifnextchar in expl3 (which is the one I'm trying to adapt).



I have defined an environment (listcontent) using xparse which encapsulates filecontentdef (which is verbatim plus macro) using the argument !O{} and key = val which works well if ALWAYS pass the optional argument.



My idea is to be able to write the environment without having to use an empty optional argument [], this is where I am lost, I have read the documentation of peek_meaning:NF but I do not understand it at all (the catcodes is confusing for me).



It works correctly if I use it in the following way:



begin{listcontents}[]
begin{listcontents}[key=val]
begin{listcontents}[
key=val
]


and I would like to do it in the following way



begin{listcontents}
begin{listcontents}
[not key = value, only a bracket whit text]


that is, if you do not find [key = val] right after }, insert a line ending ^^M and [not key = value, only a bracket whit text] would be recorded by the environment.



This is my sample file:



documentclass{article}
usepackage{fancyvrb,filecontentsdef,xparse}
begin{document}
makeatletter

ExplSyntaxOn
keys_define:nn { listcontents }
{
save-env .tl_set:N = l_env_save_tl,
save-env .initial:n = content,
show-env .bool_set:N = l_env_show_tl,
show-env .initial:n = true,
name-tmp .tl_set:N = l_tmp_name_tl,
name-tmp .initial:n = jobname.tsc,
save-macro .bool_set:N = l_save_macro_tl,
save-macro .initial:n = true,
}

NewDocumentEnvironment{ listcontents }{ !O{} }
{
group_begin:
IfNoValueF { #1 } { keys_set:nn { listcontents } { #1 } }
%peek_meaning_ignore_spaces:NF [ { char_set_catcode_active:N ^^M char_set_catcode_end_line:N ^^M \ }
%peek_meaning:NF c_space_tl { char_set_catcode_active:N ^^M char_set_catcode_end_line:N ^^M ^^M }
deffilecontentsdef {@tempswafalsefilec@ntentsdef}%
filecontentsdef{ l_tmp_name_tl }{ l_tmpa_tl }
}
{
endfilecontentsdef
group_end:
group_begin:
IfNoValueF { #1 } { keys_set:nn { listcontents } { #1 } }
IfBooleanT{ l_env_show_tl } { filecontentsexecl_tmpa_tl }
group_end:
}
ExplSyntaxOff
makeatother
section{Correct}
begin{listcontents}[show-env=true]
This is correct, use:
% some comented lines
begin{verbatim}
begin{listcontents}[show-env=true]
end{verbatim}
end{listcontents}

The textbf{file generate} is:
VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

begin{listcontents}[
show-env=true
]
This is correct, use:
% some comented lines
begin{verbatim*}
begin{listcontents}[
show-env=true
]
end{verbatim*}
end{listcontents}

The textbf{file generate} is:

VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par


begin{listcontents}[]
This is correct, use empty []:
% some comented lines
begin{verbatim*}
begin{listcontents}[]
end{verbatim*}
end{listcontents}

The textbf{file generate} is:
VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

section{No Correct}
begin{listcontents} [NO optional argument]
This is correct for key=val , use space before [] :
% some comented lines
begin{verbatim*}
begin{listcontents} [NO optional argument]
end{verbatim*}
but verb*+[NO optional argument]+ its not save in macro
and the space between the letters has disappeared.
end{listcontents}

The textbf{file generate} is:
VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

begin{listcontents}
This is what I want to happen when I omit []
% some comented lines
begin{verbatim*}
begin{listcontents}
This is what I want to happen when I omit []
% some comented lines
end{verbatim*}
but verb*+[NO optional argument]+ its not save in macro
and space between the letters and first line has disappeared.
end{listcontents}

The textbf{file generate} is:
VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc}

end{document}


Can this be done using xparse/expl3?



regards










share|improve this question



























    0















    this query is related to How to pass an optional argument to an environment with verbatim content? (whose solution did not work in my case) and with Emulating @ifnextchar in expl3 (which is the one I'm trying to adapt).



    I have defined an environment (listcontent) using xparse which encapsulates filecontentdef (which is verbatim plus macro) using the argument !O{} and key = val which works well if ALWAYS pass the optional argument.



    My idea is to be able to write the environment without having to use an empty optional argument [], this is where I am lost, I have read the documentation of peek_meaning:NF but I do not understand it at all (the catcodes is confusing for me).



    It works correctly if I use it in the following way:



    begin{listcontents}[]
    begin{listcontents}[key=val]
    begin{listcontents}[
    key=val
    ]


    and I would like to do it in the following way



    begin{listcontents}
    begin{listcontents}
    [not key = value, only a bracket whit text]


    that is, if you do not find [key = val] right after }, insert a line ending ^^M and [not key = value, only a bracket whit text] would be recorded by the environment.



    This is my sample file:



    documentclass{article}
    usepackage{fancyvrb,filecontentsdef,xparse}
    begin{document}
    makeatletter

    ExplSyntaxOn
    keys_define:nn { listcontents }
    {
    save-env .tl_set:N = l_env_save_tl,
    save-env .initial:n = content,
    show-env .bool_set:N = l_env_show_tl,
    show-env .initial:n = true,
    name-tmp .tl_set:N = l_tmp_name_tl,
    name-tmp .initial:n = jobname.tsc,
    save-macro .bool_set:N = l_save_macro_tl,
    save-macro .initial:n = true,
    }

    NewDocumentEnvironment{ listcontents }{ !O{} }
    {
    group_begin:
    IfNoValueF { #1 } { keys_set:nn { listcontents } { #1 } }
    %peek_meaning_ignore_spaces:NF [ { char_set_catcode_active:N ^^M char_set_catcode_end_line:N ^^M \ }
    %peek_meaning:NF c_space_tl { char_set_catcode_active:N ^^M char_set_catcode_end_line:N ^^M ^^M }
    deffilecontentsdef {@tempswafalsefilec@ntentsdef}%
    filecontentsdef{ l_tmp_name_tl }{ l_tmpa_tl }
    }
    {
    endfilecontentsdef
    group_end:
    group_begin:
    IfNoValueF { #1 } { keys_set:nn { listcontents } { #1 } }
    IfBooleanT{ l_env_show_tl } { filecontentsexecl_tmpa_tl }
    group_end:
    }
    ExplSyntaxOff
    makeatother
    section{Correct}
    begin{listcontents}[show-env=true]
    This is correct, use:
    % some comented lines
    begin{verbatim}
    begin{listcontents}[show-env=true]
    end{verbatim}
    end{listcontents}

    The textbf{file generate} is:
    VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

    begin{listcontents}[
    show-env=true
    ]
    This is correct, use:
    % some comented lines
    begin{verbatim*}
    begin{listcontents}[
    show-env=true
    ]
    end{verbatim*}
    end{listcontents}

    The textbf{file generate} is:

    VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par


    begin{listcontents}[]
    This is correct, use empty []:
    % some comented lines
    begin{verbatim*}
    begin{listcontents}[]
    end{verbatim*}
    end{listcontents}

    The textbf{file generate} is:
    VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

    section{No Correct}
    begin{listcontents} [NO optional argument]
    This is correct for key=val , use space before [] :
    % some comented lines
    begin{verbatim*}
    begin{listcontents} [NO optional argument]
    end{verbatim*}
    but verb*+[NO optional argument]+ its not save in macro
    and the space between the letters has disappeared.
    end{listcontents}

    The textbf{file generate} is:
    VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

    begin{listcontents}
    This is what I want to happen when I omit []
    % some comented lines
    begin{verbatim*}
    begin{listcontents}
    This is what I want to happen when I omit []
    % some comented lines
    end{verbatim*}
    but verb*+[NO optional argument]+ its not save in macro
    and space between the letters and first line has disappeared.
    end{listcontents}

    The textbf{file generate} is:
    VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc}

    end{document}


    Can this be done using xparse/expl3?



    regards










    share|improve this question

























      0












      0








      0








      this query is related to How to pass an optional argument to an environment with verbatim content? (whose solution did not work in my case) and with Emulating @ifnextchar in expl3 (which is the one I'm trying to adapt).



      I have defined an environment (listcontent) using xparse which encapsulates filecontentdef (which is verbatim plus macro) using the argument !O{} and key = val which works well if ALWAYS pass the optional argument.



      My idea is to be able to write the environment without having to use an empty optional argument [], this is where I am lost, I have read the documentation of peek_meaning:NF but I do not understand it at all (the catcodes is confusing for me).



      It works correctly if I use it in the following way:



      begin{listcontents}[]
      begin{listcontents}[key=val]
      begin{listcontents}[
      key=val
      ]


      and I would like to do it in the following way



      begin{listcontents}
      begin{listcontents}
      [not key = value, only a bracket whit text]


      that is, if you do not find [key = val] right after }, insert a line ending ^^M and [not key = value, only a bracket whit text] would be recorded by the environment.



      This is my sample file:



      documentclass{article}
      usepackage{fancyvrb,filecontentsdef,xparse}
      begin{document}
      makeatletter

      ExplSyntaxOn
      keys_define:nn { listcontents }
      {
      save-env .tl_set:N = l_env_save_tl,
      save-env .initial:n = content,
      show-env .bool_set:N = l_env_show_tl,
      show-env .initial:n = true,
      name-tmp .tl_set:N = l_tmp_name_tl,
      name-tmp .initial:n = jobname.tsc,
      save-macro .bool_set:N = l_save_macro_tl,
      save-macro .initial:n = true,
      }

      NewDocumentEnvironment{ listcontents }{ !O{} }
      {
      group_begin:
      IfNoValueF { #1 } { keys_set:nn { listcontents } { #1 } }
      %peek_meaning_ignore_spaces:NF [ { char_set_catcode_active:N ^^M char_set_catcode_end_line:N ^^M \ }
      %peek_meaning:NF c_space_tl { char_set_catcode_active:N ^^M char_set_catcode_end_line:N ^^M ^^M }
      deffilecontentsdef {@tempswafalsefilec@ntentsdef}%
      filecontentsdef{ l_tmp_name_tl }{ l_tmpa_tl }
      }
      {
      endfilecontentsdef
      group_end:
      group_begin:
      IfNoValueF { #1 } { keys_set:nn { listcontents } { #1 } }
      IfBooleanT{ l_env_show_tl } { filecontentsexecl_tmpa_tl }
      group_end:
      }
      ExplSyntaxOff
      makeatother
      section{Correct}
      begin{listcontents}[show-env=true]
      This is correct, use:
      % some comented lines
      begin{verbatim}
      begin{listcontents}[show-env=true]
      end{verbatim}
      end{listcontents}

      The textbf{file generate} is:
      VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

      begin{listcontents}[
      show-env=true
      ]
      This is correct, use:
      % some comented lines
      begin{verbatim*}
      begin{listcontents}[
      show-env=true
      ]
      end{verbatim*}
      end{listcontents}

      The textbf{file generate} is:

      VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par


      begin{listcontents}[]
      This is correct, use empty []:
      % some comented lines
      begin{verbatim*}
      begin{listcontents}[]
      end{verbatim*}
      end{listcontents}

      The textbf{file generate} is:
      VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

      section{No Correct}
      begin{listcontents} [NO optional argument]
      This is correct for key=val , use space before [] :
      % some comented lines
      begin{verbatim*}
      begin{listcontents} [NO optional argument]
      end{verbatim*}
      but verb*+[NO optional argument]+ its not save in macro
      and the space between the letters has disappeared.
      end{listcontents}

      The textbf{file generate} is:
      VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

      begin{listcontents}
      This is what I want to happen when I omit []
      % some comented lines
      begin{verbatim*}
      begin{listcontents}
      This is what I want to happen when I omit []
      % some comented lines
      end{verbatim*}
      but verb*+[NO optional argument]+ its not save in macro
      and space between the letters and first line has disappeared.
      end{listcontents}

      The textbf{file generate} is:
      VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc}

      end{document}


      Can this be done using xparse/expl3?



      regards










      share|improve this question














      this query is related to How to pass an optional argument to an environment with verbatim content? (whose solution did not work in my case) and with Emulating @ifnextchar in expl3 (which is the one I'm trying to adapt).



      I have defined an environment (listcontent) using xparse which encapsulates filecontentdef (which is verbatim plus macro) using the argument !O{} and key = val which works well if ALWAYS pass the optional argument.



      My idea is to be able to write the environment without having to use an empty optional argument [], this is where I am lost, I have read the documentation of peek_meaning:NF but I do not understand it at all (the catcodes is confusing for me).



      It works correctly if I use it in the following way:



      begin{listcontents}[]
      begin{listcontents}[key=val]
      begin{listcontents}[
      key=val
      ]


      and I would like to do it in the following way



      begin{listcontents}
      begin{listcontents}
      [not key = value, only a bracket whit text]


      that is, if you do not find [key = val] right after }, insert a line ending ^^M and [not key = value, only a bracket whit text] would be recorded by the environment.



      This is my sample file:



      documentclass{article}
      usepackage{fancyvrb,filecontentsdef,xparse}
      begin{document}
      makeatletter

      ExplSyntaxOn
      keys_define:nn { listcontents }
      {
      save-env .tl_set:N = l_env_save_tl,
      save-env .initial:n = content,
      show-env .bool_set:N = l_env_show_tl,
      show-env .initial:n = true,
      name-tmp .tl_set:N = l_tmp_name_tl,
      name-tmp .initial:n = jobname.tsc,
      save-macro .bool_set:N = l_save_macro_tl,
      save-macro .initial:n = true,
      }

      NewDocumentEnvironment{ listcontents }{ !O{} }
      {
      group_begin:
      IfNoValueF { #1 } { keys_set:nn { listcontents } { #1 } }
      %peek_meaning_ignore_spaces:NF [ { char_set_catcode_active:N ^^M char_set_catcode_end_line:N ^^M \ }
      %peek_meaning:NF c_space_tl { char_set_catcode_active:N ^^M char_set_catcode_end_line:N ^^M ^^M }
      deffilecontentsdef {@tempswafalsefilec@ntentsdef}%
      filecontentsdef{ l_tmp_name_tl }{ l_tmpa_tl }
      }
      {
      endfilecontentsdef
      group_end:
      group_begin:
      IfNoValueF { #1 } { keys_set:nn { listcontents } { #1 } }
      IfBooleanT{ l_env_show_tl } { filecontentsexecl_tmpa_tl }
      group_end:
      }
      ExplSyntaxOff
      makeatother
      section{Correct}
      begin{listcontents}[show-env=true]
      This is correct, use:
      % some comented lines
      begin{verbatim}
      begin{listcontents}[show-env=true]
      end{verbatim}
      end{listcontents}

      The textbf{file generate} is:
      VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

      begin{listcontents}[
      show-env=true
      ]
      This is correct, use:
      % some comented lines
      begin{verbatim*}
      begin{listcontents}[
      show-env=true
      ]
      end{verbatim*}
      end{listcontents}

      The textbf{file generate} is:

      VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par


      begin{listcontents}[]
      This is correct, use empty []:
      % some comented lines
      begin{verbatim*}
      begin{listcontents}[]
      end{verbatim*}
      end{listcontents}

      The textbf{file generate} is:
      VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

      section{No Correct}
      begin{listcontents} [NO optional argument]
      This is correct for key=val , use space before [] :
      % some comented lines
      begin{verbatim*}
      begin{listcontents} [NO optional argument]
      end{verbatim*}
      but verb*+[NO optional argument]+ its not save in macro
      and the space between the letters has disappeared.
      end{listcontents}

      The textbf{file generate} is:
      VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc} par

      begin{listcontents}
      This is what I want to happen when I omit []
      % some comented lines
      begin{verbatim*}
      begin{listcontents}
      This is what I want to happen when I omit []
      % some comented lines
      end{verbatim*}
      but verb*+[NO optional argument]+ its not save in macro
      and space between the letters and first line has disappeared.
      end{listcontents}

      The textbf{file generate} is:
      VerbatimInput[frame=single,numbers=left,numbersep=3pt]{jobname.tsc}

      end{document}


      Can this be done using xparse/expl3?



      regards







      macros expl3 xparse






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 11 mins ago









      Pablo González LPablo González L

      1,0361820




      1,0361820






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "85"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f486148%2favoid-passing-an-empty-optional-argument-an-environment-with-verbatim-content%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f486148%2favoid-passing-an-empty-optional-argument-an-environment-with-verbatim-content%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Paper upload error, “Upload failed: The top margin is 0.715 in on page 3, which is below the required...

          Emraan Hashmi Filmografia | Linki zewnętrzne | Menu nawigacyjneGulshan GroverGulshan...

          How can I write this formula?newline and italics added with leqWhy does widehat behave differently if I...