3

This question already has an answer here:

I'm preparing a small workbook. I'm using gray empty underlines as in this answer to make empty fields for handwritten text. I'm using \documentclass[a4paper,11pt]{book}.

\documentclass[a4paper,11pt]{book}
\usepackage[francais]{babel}
\usepackage{geometry}
\usepackage{xcolor}
\geometry{paperwidth=21cm,paperheight=29.7cm, body={18cm,25.7cm}, top=2.5cm, left=1.5cm}

\begin{document}
{

\frontmatter
\tableofcontents
\cleardoublepage

\mainmatter


\chapter{Hi}
Mathematics is the study of numbers, quantity, space, structure, and change. Mathematics \color{gray}\underline{\hspace{5cm}}\color{black} is used throughout the world as an essential tool in many fields, including natural science, engineering, medicine, and the social sciences. Applied mathematics, the branch of mathematics concerned with application of mathematical knowledge to other fields, inspires and makes use of new mathematical discoveries and sometimes leads to the development of entirely new mathematical disciplines, such as statistics and game theory. Mathematicians also engage in pure mathematics, or mathematics for its own sake, without having any application in mind. There is no clear line separating pure and applied mathematics, and practical applications for what began as pure mathematics are often discove

\end{document}

I get the following output

enter image description here

As you can see, the underline gets out of the margins and the word "is" following it is not shown. How can I make latex treat these fields as ordinary text so for example, in \color{gray}\underline{\hspace{5cm}}\color{black} latex should treat it as \color{gray}\underline{\hspace{1.5cm}}\color{black} \\ \color{gray}\underline{\hspace{3.5cm}}\color{black} or something like that?

marked as duplicate by user36296, egreg, Stefan Pinnow, Phelype Oleinik, Sebastiano Sep 28 '18 at 17:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

@egreg's answer https://tex.stackexchange.com/a/22199/36296 can be applied to your example:

\documentclass[a4paper,11pt]{book}

\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{geometry}
\usepackage{xcolor}

\geometry{paperwidth=21cm,paperheight=29.7cm, body={18cm,25.7cm}, top=2.5cm, left=1.5cm}

\newcommand{\piece}{\hskip1sp\kern-1sp\hbox to .5cm{\hrulefill}}
\newcommand{\nbpiece}{\hbox to .5cm{\hrulefill}}

\makeatletter
\newcommand{\build}[2]{\leavevmode
  \count@=\z@ \toks@={}%
  \loop\ifnum\count@<\numexpr#1\relax
    \toks@=\expandafter{\the\toks@#2}%
    \advance\count@\@ne
  \repeat
  \the\toks@}
\makeatletter

\newcommand{\blank}[2][1]{%
  \build{#1}{\nbpiece}\build{2*(#2-#1)}{\piece}\build{#1}{\nbpiece}}

\begin{document}

Mathematics is the study of numbers, quantity, space, structure, and change. Mathematics {\color{lightgray}\blank{5}} is used throughout the world as an essential tool in many fields, including natural science, engineering, medicine, and the social sciences. Applied mathematics, the branch of mathematics concerned with application of mathematical knowledge to other fields, inspires and makes use of new mathematical discoveries and sometimes leads to the development of entirely new mathematical disciplines, such as statistics and game theory. Mathematicians also engage in pure mathematics, or mathematics for its own sake, without having any application in mind. There is no clear line separating pure and applied mathematics, and practical applications for what began as pure mathematics are often discove

\end{document}

enter image description here

  • With such things it's also a good idea to increase leading, as most people have difficulty writing well in an 8 pt font ;-) – Joey Sep 28 '18 at 16:39
  • @Joey Luckily it's is 11pt and not 8pt :) but I see your point. Maybe you should lave a comment below the question to make sure the OP sees it? (Your profile image is soooo cute!) – user36296 Sep 28 '18 at 16:41
  • 1
    @Joey this functionality is included in dashundergaps! – NBur Sep 28 '18 at 17:05
3

Maybe you can try the dashundergaps package. See documentation.

\documentclass[a4paper,11pt]{book}
\usepackage[francais]{babel}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage{dashundergaps}
\geometry{paperwidth=21cm,paperheight=29.7cm, body={18cm,25.7cm}, top=2.5cm, left=1.5cm}

\dashundergapssetup{
    ,teacher-mode = true
    ,gap-numbers = false
    %,gap-number-format  = \,\textsuperscript{\normalfont(\thegapnumber)}
    ,gap-font           = \itshape
    ,teacher-gap-format = underline
    ,gap-widen
    ,gap-extend-percent=20
}

\begin{document}
    {

        \frontmatter
        \tableofcontents
        \cleardoublepage

        \mainmatter


        \chapter{Hi}
        Mathematics is the study of numbers, quantity, space, structure, and change. Mathematics \gap{Empty box in student mode} is used throughout the world as an essential tool in many fields, including natural science, engineering, medicine, and the social sciences. Applied mathematics, the branch of mathematics concerned with application of mathematical knowledge to other fields, inspires and makes use of new mathematical discoveries and sometimes leads to the development of entirely new mathematical disciplines, such as statistics and game theory. Mathematicians also engage in pure mathematics, or mathematics for its own sake, without having any application in mind. There is no clear line separating pure and applied mathematics, and practical applications for what began as pure mathematics are often discove

\end{document}
  • Great package for teachers and publishers. – BPP Sep 28 '18 at 15:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.