I defined a new command for my novel method so that I can use it all over my document (and also easily change it later when I find a better one). I noticed that this results in lines running into the margins when my method name has a specific length. Here is a minimal example:
\documentclass[12pt]{article}
\usepackage[a4paper, left=2cm, top=2cm, bottom=2cm, right=4cm]{geometry}
\newcommand{\methodname}{MyMethod}
\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy \methodname~ eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
\end{document}
As you can see, the first line first line is not rendered nicely. When I choose a longer name, at some point, the method name gets hyphenated but it still runs over the margin.
What is the source of the issue and what are the best ways to overcome it?


