1

I'm coding a LaTeX interface for mscgen (another one) and I'm using fancyvrb::VerbatimOut inside a newenvironment to output a part of the tex file into an external file, process it, then import the generated picture.

The signalling chart is indented using tabs (yeah, I know, it's evil) and VerbatimOut does it's job by writing everything 'as-is' into the external file. However, mscgen doesn't likes tab characters, so I'd like to know if it is possible to remove certain characters (or replace them) while using VerbatimOut.

Something like :

\RequirePackage{fancyvrb}

\newenvironment{test}[1]
    {\VerbatimOut[codes={\catcode`\^^I=9}]{#1}}
    {\endVerbatimOut}

Or :

\RequirePackage{fancyvrb}

\newenvironment{test}[1]
    {\begingroup\catcode9=9\relax\VerbatimOut{#1}}
    {\endVerbatimOut\catcode9=10\relax\endgroup}

Of course there is more code around, but the idea is to get the escaped text without the tabs, or at least replaced with no more than one space instead :

\begin{test}{external_file.txt}
This\n
    is\n
#       a    great     \n
            test\n
\end{test}

Should produce the following file 'external_file.txt' :

This\n
is\n
# a great \n
test\n

Got some information from the following links :

https://en.wikibooks.org/wiki/TeX/catcode

Tab not as extra alignment tab

How to output a tabulation into a file

How to redefine characters as alignment tabs in a table

Yet I cannot get them to work as I intend.

Or maybe there's a mscgen option to remove input characters, but I didn't found it.

1 Answer 1

1

This seems to work:

\documentclass{article}
\usepackage{fancyvrb}

\newenvironment{test}[1]
 {\VerbatimEnvironment\VerbatimOut[codes={\catcode`\^^I=9}]{#1}}
 {\endVerbatimOut}

\begin{document}

\begin{test}{\jobname.test}
This line has no tab
    This line has one tab
        This line has two tabs
This line has no tab
\end{test}

\VerbatimInput{\jobname.test}

\end{document}

Here's the output file I get:

This line has no tab
This line has one tab
This line has two tabs
This line has no tab

and the output witnesses it:

enter image description here

However, you might prefer \catcode`\^^I=10 so not to lose accidental tabs in the middle of a line. The initial ones will disappear nonetheless.

Note. Tabs will not appear in the code above, because of how the site treats tabs.

4
  • Yeah, not bad, I wasn't that far from the truth :) Loosing in the middle of the line is no problem for me, because there are "tabular-like" indentations that also gets output weirdly by mscgen. However it's a bit too hard as "text | text" gets converted into "text| text". If it could be converted in at least one space "that would be great" (insert office space's meme here).
    – Kochise
    Nov 14, 2020 at 9:12
  • @Kochise I tried installing mscgen and adding tabs at the beginning of the lines in their example file; the conversion was flawless. Not sure what the comment is about: if you change the catcode to 10 instead of 9, tabs in the middle of a line will become a space.
    – egreg
    Nov 14, 2020 at 9:24
  • I tried and tried yesterday, all combinations, nothing worked. This morning, I try again the solution you provided, it worked (even tried a late attempt using Ctrl+Z to be sure). Who the Hell touched my computer during the night ? Some sort of computer leprechaun ? Anyway, just give me 5 minutes to find the best option for my usage.
    – Kochise
    Nov 14, 2020 at 9:32
  • Fabulous, catcode=10 did the trick, even collating adjacent tabs/spaces just like expected. Currently I removed \VerbatimEnvironment to test and it seems to work without it, is it mandatory ?
    – Kochise
    Nov 14, 2020 at 9:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .