Latex将新行开头的[x]解释为一个测量单位,x是一个数字.我该如何阻止它这样做



所以我有一个简单的文本,我想用乳胶渲染:\

section{Source}
[1] Some text\
[2] href{A Text}{A Link to a Website}\
[3] href{Another Text}{Another Link to a Website}\
[4] href{A 3rd Text}{A 3rd Link to a Website}

编译器抛出错误"0";非法计量单位(插入pt(";对于第2行和第4行,只正确编译带有[1]的行,并在下面的行中去掉[2]、[3]和[4]。我知道有了{},我可以使用\{和\}来获得它们,但现在我该如何为[]制作呢?

你真的不应该滥用\换行(制表符除外(

在您的情况下,这不仅是糟糕的样式,还会导致错误,因为latex将其后面的[]解释为可选参数,并期望插入垂直空间量,而不仅仅是一个普通数字。

你可以通过空行使用合适的段落:

documentclass{article}
usepackage{hyperref}
usepackage{indentfirst}
begin{document}
section{Source}
[1] Some text
[2] href{A Text}{A Link to a Website}
[3] href{Another Text}{Another Link to a Website}
[4] href{A 3rd Text}{A 3rd Link to a Website}

end{document}

或者,如果你的整个文件都由这样的行组成,你可以让latex尊重它们:

documentclass{article}
usepackage{hyperref}
usepackage{indentfirst}

begin{document}
obeylines
section{Source}
[1] Some text
[2] href{A Text}{A Link to a Website}
[3] href{Another Text}{Another Link to a Website}
[4] href{A 3rd Text}{A 3rd Link to a Website}
end{document}

我同意samcarter_is_at_topanswers.xyz的回答。我还建议使用LaTeX特定的结构,例如enumerate环境。

不过,对于直接的答案,您可以将错误解释的[]分组在花括号内

[1] Some text \
{[2]}href{A Text}{A Link to a Website}\
{[3]}href{Another Text}{Another Link to a Website}\
{[4]}href{A 3rd Text}{A 3rd Link to a Website}

此外,还可以使用lbrackrbrack替换[]

最新更新