Skip to content
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

Adjustments to \verb and +v (ltcmd) #1087

Closed
wants to merge 21 commits into from
Closed

Adjustments to \verb and +v (ltcmd) #1087

wants to merge 21 commits into from

Conversation

josephwright
Copy link
Member

Internal housekeeping

Status of pull request

  • Feedback wanted
  • Under development
  • Ready to merge

Checklist of required changes before merge will be approved

  • Test file(s) added
  • Version and date string updated in changed source files
  • Relevant \changes entries in source included
  • Relevant changes.txt updated
  • ltnewsX.tex (and/or latexchanges.tex) updated

@josephwright josephwright linked an issue Jun 14, 2023 that may be closed by this pull request
@josephwright josephwright requested review from PhelypeOleinik and FrankMittelbach and removed request for PhelypeOleinik June 14, 2023 18:42
Copy link
Member

@FrankMittelbach FrankMittelbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that it is good to provide @vobeytabs. It might complicate the situation in the field --- needs some thought

base/doc/ltnews38.tex Outdated Show resolved Hide resolved
Comment on lines 1200 to 1201
{\catcode`\^^I=\active
\gdef\@vobeytabs{\catcode`\^^I\active\let^^I\@xobeytab}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we sure that it is better to have a separate command or to stick the TAB handling into @vobeyspaces? I'm just wondering, but there are several packages out there that mimic verbatim setup and maybe they would not have to change and nevertheless pick up the ^Î handling this way. Just as thought ... not thought through

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see this both ways. I agree that if you want to say 'basically tabs are spaces' then yes, it makes sense not to have a separate macro. But the moment you handle tabs there's the possibility of diverging from space handling, and it was that I was thinking of: in particular, people could allow a tab to convert to multiple spaces in verb material.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could still be moved (by default) into @vobeyspaces (using your @vobeytabs macro) this way probably avoid all the redefs and still gains the flexibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you mean include \@vobeytabs in the def. for \@vobeyspaces?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean this originally, but yes, your argument about being able to adjust it is valid, so I now thought moving it in there gives you the best of both worlds

Comment on lines 1334 to 1344
%<latexrelease>\IncludeInRelease{2023/11/01}%
%<latexrelease> {\verbatim}{Obeyed tabs}%
%<*2ekernel|latexrelease>
\def\verbatim{\@verbatim \frenchspacing\@vobeyspaces\@vobeytabs \@xverbatim}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\verbatim}{Obeyed tabs}%
%<latexrelease>\def\verbatim{\@verbatim \frenchspacing\@vobeyspaces \@xverbatim}
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if tabs are handled inside @vobeyspaces then this hsouldn't be needed, should it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd wondered about that. However, that leaves you vulnerable - to a re-definition of \@vobeyspaces, as that would also kill tab support. That might of course be the position we want to take. So I've backed out my change and will look again at this - there's also something not quite right and I want to understand that too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way I see it is this: we interpret \@vobeyspaces as "handle all space like chars (space TAB, maybe others one day) for verbatim" and \@vobeytabs as an indirection to do something special to tabs alone on top of it. To my knowledge there is no redefinition of \vobeyspaces right now and if there is one in the future it has to take care of the assumption.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"all space-like chars"!
This could be a large number, and it can be somewhat controversial which ones are "truly space-like".
It is not even clear that TAB is always and everywhere considered space-like.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if you like the new version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how to find the latest version.

Comment on lines 1481 to 1489
% {Provide visible space in \cs{verb*} also for XeTeX and LuaTeX (github/69)}
% \changes{v1.2b}{2023/06/14}
% {Support visible tabs in \cs{verb*}}
% \begin{macrocode}
\@namedef{verbatim*}{\@verbatim
\@setupverbvisiblespace
\frenchspacing\@vobeyspaces\@sxverbatim}
\@setupverbvisibletab
\frenchspacing\@vobeyspaces\@vobeytabs\@sxverbatim}
\expandafter\let\csname endverbatim*\endcsname =\endverbatim
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines 1498 to 1503
%<latexrelease>\IncludeInRelease{2018/12/01}%
%<latexrelease> {\verbatim*}{Setup visible space for \verb}%
%<latexrelease>\@namedef{verbatim*}{\@verbatim
%<latexrelease> \@setupverbvisiblespace
%<latexrelease> \frenchspacing\@vobeyspaces\@sxverbatim}
%<latexrelease>\EndIncludeInRelease
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Comment on lines 1586 to 1589
\ifnum\catcode`\ =\active
\else \@setupverbvisiblespace \@vobeyspaces \fi
\ifnum\catcode`\^^I=\active
\else \@setupverbvisibletab \@vobeytabs \fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however in that case I'm not sure this logic is still correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed: take a look at the modified one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this?

@car222222
Copy link
Contributor

There seem to be a few comments etc that are still pending.

Copy link
Contributor

@car222222 car222222 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A typo and some replies/comments.

@@ -794,6 +794,42 @@ \subsection{Commands at the start of tabular cells}
\end{tabular}
\end{verbatim}

\subsection{Using the verbatim argument types}

As described about, the \texttt{v}-type argument may be viewed as similar to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this already got changed? Presumably: about ==> above ??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure: the diff suggests that it now reads: aboveß ??

Comment on lines 1334 to 1344
%<latexrelease>\IncludeInRelease{2023/11/01}%
%<latexrelease> {\verbatim}{Obeyed tabs}%
%<*2ekernel|latexrelease>
\def\verbatim{\@verbatim \frenchspacing\@vobeyspaces\@vobeytabs \@xverbatim}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\verbatim}{Obeyed tabs}%
%<latexrelease>\def\verbatim{\@verbatim \frenchspacing\@vobeyspaces \@xverbatim}
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"all space-like chars"!
This could be a large number, and it can be somewhat controversial which ones are "truly space-like".
It is not even clear that TAB is always and everywhere considered space-like.

Comment on lines 1334 to 1344
%<latexrelease>\IncludeInRelease{2023/11/01}%
%<latexrelease> {\verbatim}{Obeyed tabs}%
%<*2ekernel|latexrelease>
\def\verbatim{\@verbatim \frenchspacing\@vobeyspaces\@vobeytabs \@xverbatim}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\verbatim}{Obeyed tabs}%
%<latexrelease>\def\verbatim{\@verbatim \frenchspacing\@vobeyspaces \@xverbatim}
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how to find the latest version.

Comment on lines 1586 to 1589
\ifnum\catcode`\ =\active
\else \@setupverbvisiblespace \@vobeyspaces \fi
\ifnum\catcode`\^^I=\active
\else \@setupverbvisibletab \@vobeytabs \fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this?

@car222222
Copy link
Contributor

When the code is finalised I shall review the text in usrguide:
I cannot follow some parts of the current version.

@josephwright
Copy link
Member Author

When the code is finalised I shall review the text in usrguide: I cannot follow some parts of the current version.

Removed: Frank suggested activating tabs was done as part of activating spaces, so it's all in one place.

@car222222
Copy link
Contributor

What was "Removed:"?

I assume that it was not all the text in usrguide about verbatim and friends!

@josephwright
Copy link
Member Author

What was "Removed:"?

I assume that it was not all the text in usrguide about verbatim and friends!

I meant the lines you'd been talking about: Frank had various suggestions which I addressed.

@car222222
Copy link
Contributor

Aha! But I am now, at least, referring to the whole of the entry in usrguide.

@josephwright
Copy link
Member Author

Aha! But I am now, at least, referring to the whole of the entry in usrguide.

That's all still there :)

@@ -796,7 +796,7 @@ \subsection{Commands at the start of tabular cells}

\subsection{Using the verbatim argument types}

As described about, the \texttt{v}-type argument may be viewed as similar to
As described aboveß, the \texttt{v}-type argument may be viewed as similar to
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a typo as well ;)

@car222222
Copy link
Contributor

Is all this code now finalised? So that I can attempt to sort out the documentation.

@josephwright
Copy link
Member Author

Is all this code now finalised? So that I can attempt to sort out the documentation.

Yes no changes planned: awaiting thoughts from review

@tobiasBora
Copy link

@josephwright @FrankMittelbach Ok now it is clearer, thanks a lot. I’m curious though, how would you make the difference between \par (the token) and \par (the string), for instance in the string replacement command?

@josephwright
Copy link
Member Author

@josephwright @FrankMittelbach Ok now it is clearer, thanks a lot. I’m curious though, how would you make the difference between \par (the token) and \par (the string), for instance in the string replacement command?

(Aside: TeX strings are not like strings in other languages: you mean a token list.)

Using expl3, is we do something like

\tl_set:Nn \l_tmpa_tl {#1} % The grabbed tokens
\tl_replace_all:Nnn \l_tmpa_tl { \par } { [PAR] }

we would replace the \par tokens as TeX will tokenize \par as normal. However, if we switch to

\tl_set:Nn \l_tmpa_tl {#1} % The grabbed tokens
\tl_replace_all:Nxn \l_tmpa_tl { \token_to_str:N \par } { [PAR] }

then the \par is converted by \token_to_str:N to four 'other' tokens, \, p, a and r, and we would replace that string.

@tobiasBora
Copy link

Oh, so \tl_replace would be usable on strings as well. Thanks!

@car222222
Copy link
Contributor

One further typo, in ltnews38:
obeydline ==> obeyedline

I shall deal with the (slightly improved, hooray!) documentation later.

@Skillmon
Copy link
Contributor

Skillmon commented Sep 4, 2023

One could further generalise and leave one end-of-line control sequence and one begin-of-line control sequence. Would make processing line wise easier and not hurt if the default would expand to empty. If one has to insert control sequences one could as well make processing really easier and not just hard in another way (and it wouldn't hurt typesetting with an empty control sequence -- though I doubt that direct typesetting is really the most used functionality for +v).

@FrankMittelbach
Copy link
Member

FrankMittelbach commented Sep 4, 2023

One could further generalise and leave one end-of-line control sequence and one begin-of-line control sequence. Would make processing line wise easier and not hurt if the default would expand to empty. If one has to insert control sequences one could as well make processing really easier and not just hard in another way (and it wouldn't hurt typesetting with an empty control sequence -- though I doubt that direct typesetting is really the most used functionality for +v).

quite an interesting thought, worth exploring.

@car222222
Copy link
Contributor

+1 (re +v)from me on both:

@FrankMittelbach certainly any such is worth investigating.

@Skillmon on the usage of +v
But with
Questions/Requests

Please can you provide some examples of real-world usages of +v, with associated necessary/possible settings for the two commands.

These examples will be useful both for the consideration stage and as a basis for some badly needed documentation of such uses.

TIA !

@josephwright
Copy link
Member Author

Packages/classes I can find using +v

  • cprotectinside
  • ducksay
  • l3doc
  • letgut
  • nodetree-embed
  • scontents

Most of the use cases here seem to be typesetting the content rather than writing to files, etc.

@Skillmon
Copy link
Contributor

Skillmon commented Sep 6, 2023

I use +v in some documentations of mine to typeset examples and show the results next to each other. An example for this is the macro \codeexample in pxpic.dtx (using \scantokens, but writing to a temporary file would be essentially the same).

Other than that ducksay uses +v for its \AddAnimal (directly typeset with EOL turned into \tabularnewline\null via \tl_replace_all:Nnn) and for one of its argument-reading modes (which uses \scantokens as well, and replaces two consecutive EOLs to \par and a single EOL to a single space).

@daleif
Copy link
Contributor

daleif commented Sep 7, 2023

I use +v in some documentations of mine to typeset examples and show the results next to each other. An example for this is the macro \codeexample in pxpic.dtx (using \scantokens, but writing to a temporary file would be essentially the same).

Other than that ducksay uses +v for its \AddAnimal (directly typeset with EOL turned into \tabularnewline\null via \tl_replace_all:Nnn) and for one of its argument-reading modes (which uses \scantokens as well, and replaces two consecutive EOLs to \par and a single EOL to a single space).

Nice example (the \codeexample). I'm wondering, can this sort of thing also be done via envs? I have a latex book with many examples and there I use the method of writing it to disk and doing a dual input (input + lstlisting) and I've always wondered if it can be done via code alone (aka no writing to disk)

@car222222
Copy link
Contributor

It may be time to separate the changes to \verb, and friends from the ongoing v-type considerations and possibilities.

The former, where all is resolved, can thus be executed very soon now.

The latter clearly need further ideas and discussion, followed by extensions of the documentation.

@josephwright josephwright mentioned this pull request Sep 12, 2023
6 tasks
@josephwright
Copy link
Member Author

@car222222 I've pulled out the parts of the PR that only impacted on \verb, and merged those - so we now cover tabs. That will be in the pre-release, but the adjustments to v-type (both tab support and ^^M tokens) are left here to be resolved.

@josephwright
Copy link
Member Author

Marking beginning and end of each line is easy enough when grabbing, but does it really offer a significant step up over simply marking boundaries? I'm not sure I see a use case where there is a non-trivial impact.

@Skillmon
Copy link
Contributor

If you want to process the contents line wise you can simply do \def\myBOL#1\myEOL{<stuff>} and are done if you place a BOL and EOL marker. If you only place an EOL marker you're back to checking whether your loop is done after each line, even though the reading process already knew that.

@car222222
Copy link
Contributor

@Skillmon Understood, thanks!

Copy link

This PR has been automatically marked as stale because it has not had recent activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support tabs in \verb*
9 participants