LaTeX typesetting - colors and hyperlinks

1. Use color

original LaTeX \LaTeX LATE # X does not support the use of various colors. Color macro package or xcolor macro package provides color support and special instructions for PDF output to generate color

1.1 expression of color

After calling the color or xcolor macro package, we can switch colors with the following commands:

\color[⟨color-mode⟩]{⟨code⟩}
\color{⟨color-name⟩}

There are two ways to express color. One is to use color model and color code. The code uses the number of 0 ∼ 1 to represent the proportion of components Color macro package supports rgb, cmyk and gray models, while xcolor supports more models such as hsb

\large\sffamily
{\color[gray]{0.6}
60\% grey} \\
{\color[rgb]{0,1,1}
Cyan}

The second is to directly use the name to represent the color, provided that the color name has been defined (an error will be reported if it is not defined):

\large\sffamily
{\color{red} gules} \\
{\color{blue} blue}

The color macro package only defines 8 color names, and xcolor adds some. There are 19 in total, as shown in the following table:

\large\sffamily
{\color{red!40} 40\% gules}\\
{\color{blue}blue
\color{blue!50!black}Blue black
\color{black}black}\\
{\color{-red}Complementary colors of red}

We can also customize the color name through the command. Note that ⟨ color mode ⟩ here is a required parameter:

\definecolor{⟨color-name⟩}{⟨color-mode⟩}{⟨code⟩}

1.2 colored text and boxes

The original \ color command is similar to the font command \ bfseries. It makes all the contents of the typesetting become the specified color, so it is usually grouped with curly braces when used directly. color / xcolor macro packages define some color elements that are convenient for users

To enter colored text, you can use commands like \ textbf:

\textcolor[⟨color-mode⟩]{⟨code⟩}{⟨text⟩}
\textcolor{⟨color-name⟩}{⟨text⟩}

The following command constructs a box with background color, and ⟨ material ⟩ is the content in the box:

\colorbox[⟨color-mode⟩]{⟨code⟩}{⟨material⟩}
\colorbox{⟨color-name⟩}{⟨material⟩}

The following command constructs a box with background color and colored border, ⟨ fcode ⟩ or ⟨ fcolor name ⟩ is used to set the border color:

\fcolorbox[⟨color-mode⟩]{⟨fcode⟩}{⟨code⟩}{⟨material⟩}
\fcolorbox{⟨fcolor-name⟩}{⟨color-name⟩}{⟨material⟩}

For example:

\sffamily
 Text use\textcolor{red}{gules}emphasize\\
\colorbox[gray]{0.95}{Light gray background} \\
\fcolorbox{blue}{yellow}{%
\textcolor{blue}{Blue Border +written words,%
Yellow background}
}

2. Use hyperlinks

PDF document format is the most popular electronic document format, and one of the most practical requirements of electronic documents is hyperlink function LaTeX \LaTeX In LATE # X, the hyperref macro package implements this function

2.1 hyperref macro package

hyperref macro package involves links all over the world LaTeX \LaTeX Every corner of LATE} X - directories, citations, footnotes, indexes, references, etc. are encapsulated into hyperlinks However, this also increases the possibility of conflict with other macro packages. Although macro packages have tried their best to solve all aspects of compatibility, they still can't cover all aspects In order to reduce possible conflicts, customary hyperref macro packets are placed after other macro packages.

The hyperref macro package provides commands \ hypersetup to configure various parameters Parameter can also be used as a macro package option. When calling a macro package, specify:

\hypersetup{⟨option1⟩,⟨option2⟩={value},...}
\usepackage[⟨option1⟩,⟨option2⟩={value},...]{hyperref}

The available parameters are shown in the following table:

2.2 hyperlinks

The hyperref macro package provides commands to directly write hyperlinks, which are used to generate URL s in PDF:

\url{⟨url⟩}
\nolinkurl{⟨url⟩}

\Both URL and \ nolinkurl output a url like the copy command \ verb. The difference is that the former also adds a hyperlink to the URL, while the latter does not

In the URL as a parameter in the \ URL command, you can directly enter special symbols such as%, & and so on

We can also use a paragraph of text as a hyperlink like a hyperlink in HTML:

\href{⟨url⟩}{⟨text⟩}

For example:

\url{http://wikipedia.org} \\
\nolinkurl{http://wikipedia.org} \\
\href{http://wikipedia.org}{Wiki}

After using the hyperref macro package, all references, references, indexes, etc. in the document are converted into hyperlinks The user-defined label is usually a required label (note that the label f can also be used as an optional label):

\hyperref[⟨label⟩]{⟨text⟩}

The default hyperlink adds a colored border outside the text (the border will not print when printing PDF). You can specify the colorlinks parameter to add color to the text itself, or modify the pdfborder parameter to adjust the border width to "remove" the border; Hyperlinks do not change color if you add the. Drops parameter

\hypersetup{hidelinks}
% or:
\hypersetup{pdfborder={0 0 0}}

2.3 PDF bookmarks

Another powerful feature of the hyperref macro package is to generate bookmarks for PDF For Chapter commands such as \ chapter and \ section, bookmarks will be automatically generated for PDF by default Similar to cross reference and index, bookmark generation also requires multiple compilation of source code, and the bookmark record is written in the first compilation out file, the bookmark is generated correctly after the second compilation

hyperref also provides commands to manually generate Bookmarks:

\pdfbookmark[⟨level⟩]{⟨bookmark⟩}{⟨anchor⟩}

⟨ bookmark ⟩ is the bookmark name and ⟨ anchor ⟩ is the anchor used by the bookmark item (similar to the label of cross reference) The optional parameter ⟨ level ⟩ is the bookmark level, and the default is 0 0 0.

Chapter commands often have LaTeX \LaTeX LATE ^ X commands even mathematical formulas, while PDF bookmarks are plain text. It is difficult to deal with commands and formulas and there is a risk of errors The hyperref macro package has processed many common commands for us, such as \ LaTeX and font command \ textbf. For unprocessed commands or mathematical formulas, the following commands should be used in the chapter title, which are provided respectively LaTeX \LaTeX Plain text available for LATE # X code and PDF Bookmarks:

\texorpdfstring{⟨LATEX code⟩}{⟨PDF bookmark text⟩}

For example, use the formula in the chapter name E = m c 2 E = mc^2 E=mc2, while bookmarks use E=mc^2 in plain text:

\section{Mass energy formula\texorpdfstring{$E=mc^2$}{E=mc\textasciicircum 2}}

Keywords: Latex

Added by damnedbee on Mon, 07 Mar 2022 16:41:55 +0200