How are the command names on the side in CTAN docs typeset

geometrymarginpar

Trying to figure out how they place the command names on the left margin on package docs on CTAN, e.g.

enter image description here

I have tried using marginpar, but my text is not properly aligned. Minimal example:

\documentclass{article}

\usepackage[a4paper,left=6cm,top=2cm,right=2cm,bottom=2cm]{geometry}
\usepackage{marginnote}
\usepackage{lipsum}  

\begin{document}

\reversemarginpar\marginpar{\raggedright SomeCommand}%
\lipsum[1]

\end{document}

Result:

enter image description here

Obviously, the text on the left is not aligned to the first line of the paragraph, which is the desired effect. I am also interested in having the text on the left to use \ttfamily.

How should I proceed?

Best Answer

The alignment is messed up because marginpar is being invoked in vertical mode. A \leavevmode remedies the issue. As to \ttfamily, it can just be added to the marginpar.

\documentclass{article}

\usepackage[a4paper,left=6cm,top=2cm,right=2cm,bottom=2cm]{geometry}
\usepackage{marginnote}
\usepackage{lipsum}  

\begin{document}

\leavevmode\reversemarginpar\marginpar{\raggedright\ttfamily SomeCommand}%
\lipsum[1]

\end{document}

enter image description here

If you wish to get the backslash for a command name in such a context, just use the \char'134 primitive, as in

\leavevmode\reversemarginpar\marginpar{\raggedright\ttfamily\char'134
 SomeCommand}