I've got a macro to insert a blank for fill-in-the-blank questions on my tests, but when it is at the beginning of a line, it breaks the paragraph right after the blank and the rest of the question moves down. Everything is working when the blank ends up in the midst or end of a line, though. I can get it to not break to a new paragraph, but I have to put a slashed space before it and I don't like the extra space.
My macro is:
\newcommand{\plongblank}%
{\hbox to 1.2in {\rule[.1in]{0in}{.15in}%
{\hrulefill}}}%
(The rule is a strut to give the students room to write if this falls in a 2nd or later line of the question.)
I found and adapted this answer by egreg (Thanks!) to my needs, but I can't figure out why his works and mine doesn't? I'm guessing it is the penalty and +/- stretch, but I'd really like to know for sure and why.
Here's a MWE for completeness:
\documentclass{article}
\newcommand{\plongblank}%
{\hbox to 1.2in {\rule[.1in]{0in}{.15in}%
{\hrulefill}}}%
\newcommand{\blank}[2][100]{\hfil\penalty#1\hfilneg\rule[.1in]{0in}{.15in}%
\rule[-3pt]{#2}{0.5pt}}
% commenting this out makes the paragraph break evident
%\setlength{\parindent}{0pt}
\begin{document}
When passing parameters to a function by value, any changes that the function
makes to the parameters
\plongblank{}
%\blank{1.2in}
reflected in the variables passed to the function in the calling function.
\plongblank{}
%\ \plongblank{}
%\blank{1.2in}
describes the functionality in C++ where 2 or more functions share the same
name, and the determination of which function is called is based on the number
and/or type of parameters that are being passed.
\end{document}
\leavevmode
before\hbox
?