3

This is the output of pdflatex: PDF snapshot

The relevant LaTeX line is:

You can similarly enable the third and fourth channel by giving \texttt{HIGH} input to \icpin{9}{EN3,4}.

Here is how I defined the \icpin command:

\newcommand{\icpin}[2]{\setlength{\fboxsep}{0pt} \fbox{\texttt{\colorbox{lgray}{\strut{}\,PIN~#1\,}\,#2\,}} \setlength{\fboxsep}{2pt}}

I guess the problem is in the command I defined. How do I force the line break not to come just before a period?

I tried using \@ after the period, did not solve the problem.

  • Welcome to TeX.SE. Try removing the space before \setlength. Also, while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Oh, you also have a \, at the end which probably needs to be removed. – Peter Grill Jul 28 '16 at 5:19
2

The definition you give has two spaces that you should remove

\newcommand{\icpin}[2]{\setlength{\fboxsep}{0pt} \fbox{\texttt{\colorbox{lgray}{\strut{}\,PIN~#1\,}\,#2\,}} \setlength{\fboxsep}{2pt}}
                                                ^                                                          ^

Here's a properly formatted one, with some changes:

\newcommand{\icpin}[2]{%
  \begingroup
  \setlength{\fboxsep}{0pt}%
  \fbox{%
    \ttfamily
    \colorbox{lgray}{\strut\,PIN~#1\,}\,#2\,%
  }%
  \endgroup
}

The group makes the settIng to \fboxsep local to it, so you don't need to explicitly reset it. Using \ttfamily avoids a further pair of braces: the group will limit the effect of this declaration.

Full code:

\documentclass{article}
\usepackage{xcolor}

\definecolor{lgray}{gray}{0.7}

\newcommand{\icpin}[2]{%
  \begingroup
  \setlength{\fboxsep}{0pt}%
  \fbox{%
    \ttfamily
    \colorbox{lgray}{\strut\,PIN~#1\,}\,#2\,%
  }%
  \endgroup
}

\begin{document}

You can similarly enable the third and fourth channel
by giving \texttt{HIGH} input to \icpin{9}{EN3,4}.

\end{document}

enter image description here

Perhaps you should add also thin spaces at either end.

\documentclass{article}
\usepackage{xcolor}

\definecolor{lgray}{gray}{0.7}

\newcommand{\icpin}[2]{%
  \begingroup
  \setlength{\fboxsep}{0pt}%
  \leavevmode\,% <-- don't forget \leavevmode
  \fbox{%
    \ttfamily
    \colorbox{lgray}{\strut\,PIN~#1\,}\,#2\,%
  }%
  \,%
  \endgroup
}

\begin{document}

You can similarly enable the third and fourth channel
by giving \texttt{HIGH} input to \icpin{9}{EN3,4}.

\end{document}

enter image description here

|improve this answer|||||
1

Removing the \, and the extra spaces seems to make the period attached to the box. Here is a beofre and after image:

enter image description here

enter image description here

Code:

\documentclass{article}
\usepackage{xcolor}

\newcommand{\icpin}[2]{%
    \setlength{\fboxsep}{0pt}%
    \fbox{\texttt{\colorbox{gray}{\strut{}\,PIN~#1\,}\,#2}}%
    \setlength{\fboxsep}{2pt}%
}%

\begin{document}
You can similarly enable the third and fourth channel by giving \texttt{HIGH} input to \icpin{9}{EN3,4}.

\end{document}
|improve this answer|||||
  • Removing the last \, was not necessary, removing the spaces solved the problem. – Fauzan Jul 28 '16 at 10:32

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.