I have a problem I do not know how to handle:
I need to include some small words of code - these can sometimes be longer names of something.
To display this is a name of a code piece, I've made a small command, \code{...} which wraps the ... in a special font.
But when the ... gets too long, the text exceeds my margins of the page.
MWE:
\documentclass[a4paper]{article}
\usepackage{showframe} % Just to show the frames
%A font for code
\newcommand{\code}[1]{{\fontfamily{pcr}\selectfont #1}}
\begin{document}
This is a longer line -- notice what happens now at the end: \code{OfThisLongPeiceOfText}
\end{document}
Any suggestions to how I can fix this?
Forcing a \\ when I see it gives me problems or split it up with \code{firstPart}\code{SecondPart} ?





\newcommand{\code}[1]{\@tfor\@temp:=#1\do{{\fontfamily{pcr}\selectfont\@temp}\allowbreak}}– Sunilkumar KS Nov 26 '15 at 13:03LaTeX Error: Command \ unavailable in encoding OT1. [...ow at the end: \code{OfThisLongPeiceOfText}]. It looks like it does not recognize the\allowbreak– Rasmus Bækgaard Nov 26 '15 at 13:07`\documentclass[a4paper]{article}
\usepackage{showframe}
\makeatletter \newcommand{\code}[1]{@tfor@temp:=#1\do{{\fontfamily{pcr}\selectfont@temp}\allowbreak}}
\begin{document} This is a longer line -- notice what happens now at the end: \code{OfThsLongPeiceOfText}
\end{document}`
– Sunilkumar KS Nov 26 '15 at 13:11\usepackage[T1]{fontenc}– Sunilkumar KS Nov 26 '15 at 13:13T1: http://imgur.com/YW35Qen. Is it my compiler? – Rasmus Bækgaard Nov 26 '15 at 13:14Undefined control sequenceerror for\codein http://imgur.com/YW35Qen! – Sunilkumar KS Nov 26 '15 at 13:27\sloppy- it makes the spaces way too big. – Rasmus Bækgaard Nov 26 '15 at 13:34