I would like to type something like this:
|--1-23-|--4-5---|
and get such output that every |
is a vertical line, every -
appears like \rule[.8ex]{1em}{.5pt}
, and all other (non-active) characters are in a hbox of the same width (e.g. \hbox to 1em{\hss\the\token\hss
).
I can make a macro \fw
that makes its argument to those hboxes of fixed width (as in the comment here: Can I turn a variable width font into a fixed-width font?). However, I'm struggling with how to call it without writing the argument with braces.
I made -
to active character and tried to check whether the next character is also -
. If yes, I just print the rule, and if not, I want to call \fw
with an argument delimited by the next -
. However, this doesn't work because 1) it takes the \fi
at the end of if
also as part of the argument, and that breaks things (at least that is what I understood from the log), 2) it consumes the final -
and I might want to use it again for beginning of fixed width text, and 3) I'm confused about where to properly start and end groups.
Another option would be to use fixed width somehow on the whole line/paragraph, but that would also affect those |
, and I also didn't find how to handle active characters here.
I was also thinking about using token register to read the tokens first and then decide what to do but I don't know how to use them and how to then decide what to do with which token.
Edit: I forgot to mention there might be also more instances of |
inside of the word.
\MakeShortVerb
from the doc or verbatim package that lets you use|--12--3--4|
you would just need to modify it slightly to re-add the rules|--1-23-|--4-5---|
- this can be taken for a leading|
, trailed by an arbitrary sequence of|
-delimited arguments.The question is: How to detect the last|
? Having TeX look ahead until reaching the end of the file? (An loop can be implemented which recursively gathers things in verbatim-catcode-régime until reaching either|
or the end of the file. If reaching|
process as as another|
-delimited argument, probably retokenizing things using\scantokens
and continue. If reaching the eof, pass to\scantokens
for re-tokenization and processing as usual and terminate. )