2

I have defined some small macro to markup function names:

\lstdefinestyle{inline-funcname}{
    columns=fullflexible,
    breaklines=false,
    %Note: \usefont{OML}{cmm}{m}{it} is exactly like \mathnormal
    basicstyle=\usefont{OML}{cmm}{m}{it} %\itshape\ttfamily
}
\newcommand{\ifuncname}[1]{\lstinline[style=inline-funcname]{#1}}

It works great.

The only case where it is sometimes a bit messed up is at the end of lines:

screenshot

Is there a way to make that better or avoid that fully?

  • So where should it break the contents? Remember that RedutionMatrices_Calc is not a known "word" in the language your using (...anywhere, for that matter). So, without any indication of hyphening pattern, TeX won't do anything. – Werner Jun 11 '13 at 0:51
  • Well, I guess the best thing in this case would be to stretch the rest of the line more and put it on the next line. Just like it would do with another long word which is not breakable in the middle? – Albert Jun 11 '13 at 0:53
  • 1
    I think the best way would be to rephrase your first sentence. Put the class name at the beginning like The function x in the class y implements the algorithm ... – Mensch Aug 12 '13 at 14:35
  • @Werner Could you make an answer from your comment here? – Joseph Wright Aug 3 '14 at 19:11
1

Remember that ReductionMatrices_Calc is not a known "word" in the language your using (...anywhere, for that matter). So, without any indication of hyphening pattern, TeX won't do anything. The easiest solution would be to slightly rephrase the paragraph so that it doesn't put ReductionMatrices_Calc around the line-break. Perhaps

The function \ifuncname{calcMatrix} in the class \ifuncname{ReductionMatrices_Calc}
implements the algorithm ...

Finally, while it doesn't really make a difference here, you could also use the following implementation of \ifuncname:

\newcommand{\ifuncname}{\lstinline[style=inline-funcname]}

Note that I've removed the argument capturing of \ifuncname, relying on the replacement text to take care of that. This is sometimes helpful when dealing with category changes in macro arguments. However, listings handles these quote well.

Following some ideas from Underscore makes text go past end of line into margins you can also issue a \linebreak:

enter image description here

\documentclass{article}
\usepackage[margin=1.5in]{geometry}% Just for this example
\usepackage{listings}
\lstdefinestyle{inline-funcname}{
    columns=fullflexible,
    breaklines=false,
    %Note: \usefont{OML}{cmm}{m}{it} is exactly like \mathnormal
    basicstyle=\usefont{OML}{cmm}{m}{it} %\itshape\ttfamily
}
\newcommand{\ifuncname}{\lstinline[style=inline-funcname]}

\begin{document}

\noindent
This algorithm has been implemented in the function \ifuncname{calcMatrix} in the class\linebreak \ifuncname{ReductionMatrices_Calc}
in the file \verb|algo_cpp.cpp|. All the state and parameters are stored in the class so that we
need to copy as little data as possible for successive $S \in \mathcal{P}_2(\mathcal{O})$. That is also why the iteration
through different $S \in \mathcal{P}_2(\mathcal{O})$ (see section~4.4) has been done in C++.

\end{document}

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.