4

I'm having problem in representing special characters in a PDF document as they are, without being interpreted by latex.

To not mistakenly take my question as a duplicate, let me explain what's my intent and how far I have gone with it.

I'm trying to make a PDF document containing pair of username and passphrasees each in one line, and having hyphen character filled between each pair. So far, I made this possible by following lines of code:

\documentclass[a4paper,oneside,12pt]{article}

\newcommand{\dashfill}{
    \leavevmode\xleaders\hbox{-}\hfill\kern0pt
}

\begin{document}
\noindent
1. [email protected] \dashfill passphrase
\end{document}

Notice the new command \dashfill I found in other threads. This will cause trouble as I'm explaining further.

First problem raised when I realized passphrases contain special characters which will be interpreted by latex, for example:

\begin{document}
1. [email protected] \dashfill not all $characters$ are accepted
\end{document}

Which results this output:

enter image description here

Of course, this is not acceptable as the dollar sign $ character gets missed, and this is only one character, there can be many more special characters in passphrases and as they are dynamically generated, I cannot tell which characters need to be escaped, if they can be.

I searched and realized that there is a \verbatim block, but it's not an answer because \dashfill command or any other commands don't work within that block (please tell me otherwise):

\begin{verbatim}
1. [email protected] \dashfill not all $characters$ are accepted
\end{verbatim}

enter image description here

The desire output has the form of:

01. [email protected] ---- P@$$phr@$e

Having that, username and passphrase parts should be printed as is on document, and the \dashfill command between them should be interpreted.

I searched for inline verbatim and similar, I found this solution:

\documentclass[a4paper,oneside,12pt]{article}

\newcommand{\dashfill}{
    \leavevmode\xleaders\hbox{-}\hfill\kern0pt
}

\begin{document}
\noindent
\expandafter\string\csname 01. [email protected] \endcsname
\dashfill
\expandafter\string\csname passphrase \endcsname\\
\end{document}

enter image description here

Though it seems like improvement, still there are major problems with it:

  1. There are still characters not being printed like underscore _, as the word With was surrounded by it.
  2. There's a strange quote character before username and passphrase section.

I'm lost with the complexity of LaTeX!
But there should be a way to see username and passphrases as desired. Is it?

2
  • 1
    Try \verb|whatever| . The | is chosen arbitrarily. It can be anything that‘s not in the enclosed string. Does it change anything?
    – MS-SPO
    Sep 7, 2022 at 14:16
  • @MS-SPO Tried that, it works except that another problem raises. What if there's a | or in other case "the delimiter" in the passphrase? I'm looking if it's possible to have multi-character delimiters. Or if I'm having it all wrong thinking of open-close characters as delimiters. I'll work around it, thanks. Sep 7, 2022 at 14:50

1 Answer 1

7

Absorb the passphrase verbatim:

\documentclass[a4paper,oneside,12pt]{article}

\newcommand{\dashfill}{% <--- don't forget
  \leavevmode\xleaders\hbox{-}\hfill\kern0pt
}

\NewDocumentCommand{\passphrase}{mv}{%
  \texttt{#1}~\dashfill~\texttt{#2}%
}

\begin{document}

\begin{enumerate}

\item\passphrase{[email protected]}{passphrase}

\item\passphrase{[email protected]}{&6^00-\\uu%}

\item\passphrase{[email protected]}|&{6^00-\\uu%|

\end{enumerate}

\end{document}

You can see that you can even have unmatched braces in the passphrase, so long as you delimit it with a character that's not in it (in this case |).

enter image description here

If you're running a LaTeX version prior to October 2021, you may need to add \usepackage{xparse}.

2
  • Heartiest congrats for 1 million points, hope you are the first one, achieved this...
    – MadyYuvi
    Sep 7, 2022 at 14:25
  • 1
    Your answer targeted my question so accurately it should be printed and hanged on my wall! Thanks. Happy crossing over 1M points by the way. Sep 7, 2022 at 14:44

You must log in to answer this question.

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