Skip to content

Colour and links

LaTeX Lesson 13 2:01 English narration · English + 中文 subtitles burned in

space play · ←/→ 5s · j/l 10s · f fullscreen · ,/. speed

Chapters

Transcript
Colour comes from the xcolor package. 颜色来自 xcolor 宏包。
Load it in the preamble, then wrap words in textcolor with the colour name first and the words second. 在导言区加载它,然后用 \textcolor 把词包起来, 第一对花括号写颜色名,第二对写文字。
Notice the shape: a command, two sets of braces, exactly like textbf back in lesson three. 注意这个形状:一条命令,两组花括号, 和第 3 课里的 \textbf 一模一样。
It is the same wrapping shape you already know, with one extra argument. 还是你已经认识的那个包裹形状,只是多了一个参数。
There are built-in names for the obvious colours — red, blue, green, orange, gray and more. 常见颜色都有内置的名字——红、蓝、绿、橙、灰等等。
And you can dilute one with a number: red bang sixty means sixty percent red, which is a lighter shade. 而你可以用一个数字把某个颜色调淡: red!60 表示 60% 的红,也就是浅一点的那个色调。
Colorbox is the other one worth knowing: it puts a highlight behind the words instead of colouring them. 另一个值得知道的是 \colorbox: 它在文字后面加一块底色,而不是给文字本身上色。
The hyperref package turns addresses into real links. hyperref 宏包把网址变成真正的链接。
Href takes the address first and the text to show second, and the result is clickable in the PDF. \href 第一个花括号写地址,第二个写要显示的文字, 结果在 PDF 里是可以点的。
And it does more than that quietly: every ref and every cite from the last two lessons becomes a link inside the document, so a reader can jump to the section or the source you pointed at. 而它还悄悄做了更多: 前两课里的每一个 \ref 和 \cite 都会变成文档内部的链接, 读者可以直接跳到你指向的那一节或那条来源。
One ordering rule, and it is not guessable. 有一条顺序规则,而且它是猜不到的。
Hyperref must be loaded LAST, after every other package. hyperref 必须最后加载,排在其他所有宏包之后。
The reason is that it rewrites commands other packages define, so it has to see them first. 原因是它会改写别的宏包定义的命令,所以它必须先看到它们。
Load it early and things break in small strange ways with no error at all — which is much harder to debug than a message would be. 提早加载,东西就会以各种奇怪的小方式坏掉,而且完全不报错—— 这比给你一条报错信息要难查得多。
Four things to take with you. 带走四点。
One: xcolor gives you textcolor and colorbox. 第一:xcolor 给你 \textcolor 和 \colorbox。
Two: a colour name with an exclamation mark and a number is diluted. 第二:颜色名加感叹号加一个数字,就是调淡。
Three: hyperref makes href, ref and cite clickable. 第三:hyperref 让 \href、\ref 和 \cite 都可点。
Four: load hyperref last, after every other package. 第四:hyperref 最后加载,排在其他所有宏包之后。
Now colour a word and add a link. 现在给一个词上色,再加一个链接。

Log in or create account

IGCSE, A-Level & AP