3

I'd like to get dots without extra spaces before and after; the rendering with babel for French is the one I'd like. I need to have breaking spaces.

\documentclass{article}

%\usepackage[french]{babel} % TO SEE THE EXPECTED SPACES.

\NewDocumentCommand{\tdocenv}{O{}m}{%
  \texttt{\textbackslash{}begin\{#2\}#1 %
          \!...\! %
          \textbackslash{}end\{#2\}}%
}

\begin{document}

\tdocenv{TEST}

\end{document}

2 Answers 2

4

You just want \@ in order to avoid end-of-sentence spacing, which doesn't happen with babel-french on because it does \frenchspacing at the outset.

\documentclass{article}

%\usepackage[french]{babel} % TO SEE THE EXPECTED SPACES.

\NewDocumentCommand{\tdocenv}{O{}m}{%
  \texttt{\string\begin\string{#2\string}#1 %
          \!...\@\! %
          \string\end\string{#2\string}}%
}

\begin{document}

\tdocenv{TEST}

\end{document}

I also show how to get real typewriter font backslash and braces.

enter image description here

It would make sense to add \frenchspacing to \ttfamily, so the problem will disappear in every case when you use \texttt.

\documentclass{article}

%\usepackage[french]{babel} % TO SEE THE EXPECTED SPACES.

\AddToHook{cmd/ttfamily/before}{\frenchspacing}

\NewDocumentCommand{\tdocenv}{O{}m}{%
  \texttt{\string\begin\string{#2\string}#1 %
          \!...\! %
          \string\end\string{#2\string}}%
}

\begin{document}

\tdocenv{TEST}

\end{document}
1
  • Great and cleaner code...
    – projetmbc
    Dec 7, 2023 at 17:39
2

You could use package ellipsis:

\documentclass{article}

\usepackage{ellipsis}

\NewDocumentCommand{\tdocenv}{O{}m}{%
  \texttt{\string\begin\string{#2\string}#1%
          \;\textellipsis\;%
          \string\end\string{#2\string}}%
}

\begin{document}

\tdocenv{TEST}

\end{document}

enter image description here

You must log in to answer this question.

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