我需要排版一些填空项目。我想写
\item We are ____ sure that his skills qualify him for the job.
代替
\newcommand{\blanks}[1][4em]{\underline{\makebox[#1]{}}}
...
\item We are \blanks sure that his skills qualify him for the job.
为了便于阅读。有人能帮助我吗?
编辑
\documentclass{article}
\usepackage{calc,url,graphicx}% or hyperref
% \newcommand*{\blanks}[1][4em]{\rule{#1}{.4pt}}
% \catcode`\_=\active
% \def_{\blanks[1em]}
% \everymath{\catcode`\_=8\relax}
% \newcommand*{\makeunderscorenormal}{\catcode`\_=8\relax}
% \newcommand*{\makeunderscoreweird}{\catcode`\_=\active}
% \newcommand*{\blank}[1]{\blanks[\widthof{#1}]}
\begin{document}
\includegraphics{a_b/1.png}
% We are ____ sure that his skills qualify him for the job.
% We are \blank{not} sure that his skills qualify him for the job.
% \url{http://www.tex_stackexchange.com}
$ 1_2 $
\end{document}
确实有效,但是
\documentclass{article}
\usepackage{calc,url,graphicx}% or hyperref
\newcommand*{\blanks}[1][4em]{\rule{#1}{.4pt}}
\catcode`\_=\active
\def_{\blanks[1em]}
\everymath{\catcode`\_=8\relax}
\newcommand*{\makeunderscorenormal}{\catcode`\_=8\relax}
\newcommand*{\makeunderscoreweird}{\catcode`\_=\active}
\newcommand*{\blank}[1]{\blanks[\widthof{#1}]}
\begin{document}
\includegraphics{a_b/1.png}
We are ____ sure that his skills qualify him for the job.
We are \blank{not} sure that his skills qualify him for the job.
\url{http://www.tex_stackexchange.com}
$ 1_2 $
\end{document}
才不是。
答案1
您可以使其_
活跃(并在数学模式中将其定义“改回”为下标)。
我还在\blank
宏中添加了一个选项,该选项可以制定与给定文本一样长的规则。
我还添加了宏\makeunderscorenormal
并将\makeunderscoreweird
其改回正常定义(即数学下标,即文本模式下的错误)。
代码
\documentclass{article}
\usepackage{calc,url}% or hyperref
\newcommand*{\blanks}[1][4em]{\rule{#1}{.4pt}}
\newcommand*{\blank}[1]{\blanks[\widthof{#1}]}
\begingroup
\catcode`\_=\active
\gdef_{\blanks[1em]}
\endgroup
\everymath{\catcode`\_=8\relax}
\newcommand*{\makeunderscorenormal}{\catcode`\_=8\relax}
\newcommand*{\makeunderscoreweird}{\catcode`\_=\active}
\begin{document}
\begin{itemize}\makeunderscoreweird
\item We are ____ sure that his skills qualify him for the job.
\item We are \blank{not} sure that his skills qualify him for the job.
\end{itemize}
\url{http://www.tex_stackexchange.com}
$ 1_2 $
\end{document}
输出
答案2
我不太热衷于修改类别代码。这是一种不修改类别代码的方法,它只会改变 的含义\_
:
\documentclass{article}
\usepackage{amsmath}% for \new@ifnextchar
\usepackage{calc}
\newcommand*{\blanks}[1][4em]{\rule{#1}{.4pt}}
\newcommand*{\blank}[1]{\blanks[\widthof{#1}]}
\makeatletter
\DeclareRobustCommand{\_}{\blanks[.5em]\@doblanks}
\def\@doblanks{%
\new@ifnextchar_{\blanks[.5em]\expandafter\@doblanks\@gobble}{}%
}
\makeatother
\begin{document}
\begin{itemize}
\item We are \____ sure that his skills qualify him for the job.
\item We are \______________ his skills qualify him for the job.
\item We are \blanks[7em] his skills qualify him for the job.
\item We are \blank{not} sure that his skills qualify him for the job.
\end{itemize}
\end{document}
第二项有 14 个下划线,对应第三项中的 7em。
如果你真的想要避免使用开头的反斜杠,则请将其_
激活:
\documentclass{article}
\usepackage{calc}
\usepackage{url}
\newcommand*{\blanks}[1][4em]{\rule{#1}{.4pt}}
\newcommand*{\blank}[1]{\blanks[\widthof{#1}]}
\begingroup\lccode`\~=`\_
\lowercase{\endgroup
\protected\def~}{\ifmmode\expandafter\sb\else\blanks[.5em]\fi}
\AtBeginDocument{
\catcode`\_=\active
\mathcode`\_="8000
}
\begin{document}
\begin{itemize}
\item We are ____ sure that his skills qualify him for the job.
\item We are ______________ his skills qualify him for the job.
\item We are \blanks[7em] his skills qualify him for the job.
\item We are \blank{not} sure that his skills qualify him for the job.
\end{itemize}
Some math $x_{1}$ and a URL \url{http://www.tex_stackexchange.com}
\end{document}