0

I've written a small LaTeX package and am preparing its documentation using ltxdockit package. I found a strange behavior about font.

Consider the following MWE.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{ltxdockit}
\begin{document}
\begin{ltxsyntax}
    \envitem{envname}[opt]{arg}

    this is an example.
\end{ltxsyntax}
\end{document}

After compiling this source with pdflatex, the result looks like this:

result of MWE

I noticed that the curly braces enclosing the beginning envname are rendered in \rmfamily, not in \ttfamily, which is weird to me.

I looked into ltxdockit.sty and found a macro \ltd@envitem, which \envitem is "\leted" inside ltxsyntax environment.

\def\ltd@envitem#1{%
  \ltd@itembreak
  \item[\textbackslash begin]\{{\ltxsyntaxfont\ltxsyntaxlabelfont#1}\}%
  \ltd@pdfbookmark{#1}{#1}%
  \begingroup
  \ltd@syntaxsetup
  \ltxsyntaxfont
  \def\@tempa{%
    \ltd@itemsave
    \itemsep\z@
    \item[\textbackslash end]\{{\ltxsyntaxfont\ltxsyntaxlabelfont#1}\}%
    \ltd@itemrest}%
  \ltd@parseargs}

However, I cannot see differences between line 3 and line 11 above except for the begin and end and don't know why curly braces' in these parts look different with respect to font family.

How can I change the font of the first curly braces to \ttfamily? Although the package author says, "users should not at­tempt its use un­less they are ca­pa­ble of deal­ing with prob­lems un­aided", I'd appreciate it if you give me some suggestions.

1

The difference between the begin and end is that \{ picks up the current font which is typically roman at the start but monospace by the end.

Clearly that's not intended, here I change both begin and end lines to move the braces inside the scope of the font change.

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{ltxdockit}
\makeatletter
\def\ltd@envitem#1{%
  \ltd@itembreak
  \item[\textbackslash begin]{\ltxsyntaxfont\{{\ltxsyntaxlabelfont#1}\}}%
  \ltd@pdfbookmark{#1}{#1}%
  \begingroup
  \ltd@syntaxsetup
  \ltxsyntaxfont
  \def\@tempa{%
    \ltd@itemsave
    \itemsep\z@
    \item[\textbackslash end]{\ltxsyntaxfont\{{\ltxsyntaxlabelfont#1}\}}%
    \ltd@itemrest}%
  \ltd@parseargs}

\makeatother
\begin{document}
\begin{ltxsyntax}
    \envitem{envname}[opt]{arg}

    this is an example.
\end{ltxsyntax}
\end{document}
1
  • Oops, I gave the same trial before posting the question, but forgot \makeatletter. All things go well thanks!
    – yudai-nkt
    May 19 '16 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.