4 LaTeX
4.1 Testing
If the Portable Document Format file would not be produced and it is cumbersome to figure out the error based on the log file then one can use pdflatex for testing the intermediate TEX-file as shown in (11)[30].
-
Usage of pdflatex.
4.2 Layout
4.2.1 Page Orientation
\begin{landscape} # 1
# 2
Here is anything but figures that needs to be displayed in landscape mode. # 3
# 4
\end{landscape} # 5
# 6
librarian::shelf(c( # 1
"formatdown" # 2
)) # 3
numbers <- c(123.456, 2e-6, 5e8, 0.23) # 4
format_power_numbers <- format_power(numbers) # 5
## Warning in format_power(numbers): `format_power()` is deprecated. Use `format_numbers()`
## which offers additional arguments and access to package options.
format_power_numbers_digits <- format_power(numbers, format = "sci", digits = 2, omit_power=NULL) # 1
## Warning in format_power(numbers, format = "sci", digits = 2, omit_power = NULL): `format_power()` is deprecated. Use `format_numbers()`
## which offers additional arguments and access to package options.
format_power_numbers_digits # 1
## [1] "$\\small 1.2 \\times 10^{2}$" "$\\small 2.0 \\times 10^{-6}$"
## [3] "$\\small 5.0 \\times 10^{8}$" "$\\small 2.3 \\times 10^{-1}$"
4.2.2 Justifying text
The example (12) shows how to center items[31(p. 64)].
\begin{center}centered item\end{center}
4.3 List of tables and figures
Normally, the caption for a list of tables and a list of figures is shown no matter whether tables or figures exist. i found a solution for only displaying a list if there’s an item available for that[32]. That code is in preamble.TEX under the corresponding caption as a comment. Using the package xassoccnt triggers the warning:
Warning: Package xassoccnt Warning: Warning: Package “calc” is loaded – this is not Warning: (xassoccnt) recommended for xassoccnt Warning: (xassoccnt)
calc is being called directly from default.LATEX and as i don’t want to modify the contents of default.LATEX, i have to live with the warning.
4.4 Reference to a page
If a referenced equation, figure, table or other item is on a different page, i also reference the page number:
… on the page .
This only works for the print output as there are no pages on a webpage.
4.6 Spacing
4.6.1 Space after macro
Using a macro without braces at the end removes the possible spacing from after it in PDF[33(p. 181)]:
`r render_nonmath_LaTeX_string_universal("\\LaTeX{}")` <text after space> # 1
# 2
`r render_nonmath_LaTeX_string_universal("\\LaTeX")` <text after space> # 3
# 4
LATEX <text after space>
LATEX <text after space>
4.7 Columns
If i want the following text to be in two columns i write:
i’m just writing some text that will be placed in two columns because it’s easier to read if the text is in two columns.
If i want the following text to be in one column, i write:
I am just writing some text that will be placed in one column because it can contain a figure or equation that does not fit in a narrower column.
# 1
\begin{multicols}{2} # 2
- titaandioksiid: \ce{TiO2}; # 3
# 4
- ränitetrakloriid: \ce{SiCl4}; # 5
# 6
- süsinikdisulfiid: \ce{CS2}; # 7
# 8
- vääveltetrafluoriid: \ce{SF4}; # 9
# 10
- liitiumsulfiid: \ce{Li2S}; # 11
# 12
- antimonpentafluoriid: \ce{SbF5}; # 13
# 14
- dilämmastikpentooksiid: \ce{N2O5}; # 15
# 16
- joodheptafluoriid: \ce{IF7}. # 17
\end{multicols} # 18
# 19
\begin{multicols}{2}
does not allow markdown’s sharp symbol. In order to tolerate captions inside a multi-column environment, the command must be redefined and used as a command without any parameters (example (13) with the listing ?? on the page )[36].
4.7.1 Head
multicols
does not show figures.
The example (14) with the listing ?? on the page shows how to decorate the vertical line between the columns[37(p. 7)].
This is just a sample text.
It is not possible to have tables created by print_table
in a multicolumn environment[38]:
! Package longtable Error: longtable not in 1-column mode.
4.9 Chinese characters
In order to display Chinese characters an appropriate main and mono font must be set in preamble.TEX.[39] lists suitable fonts, for example:
That font wasn’t available in my system, so i installed it:
After that, i was looking for Chinese fonts:
That resulted with:
/usr/share/fonts/opentype/noto/NotoSerifCJK-Bold.ttc: Noto Serif CJK SC:style=Bold
/usr/share/fonts/opentype/noto/NotoSerifCJK-Bold.ttc: Noto Serif CJK TC:style=Bold
/usr/share/fonts/opentype/noto/NotoSerifCJK-Bold.ttc: Noto Serif CJK JP:style=Bold
/usr/share/fonts/opentype/noto/NotoSerifCJK-Bold.ttc: Noto Serif CJK KR:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans CJK JP:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans CJK HK:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans CJK KR:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans CJK SC:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans CJK TC:style=Regular
/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc: Noto Serif CJK SC:style=Regular
/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc: Noto Serif CJK TC:style=Regular
/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc: Noto Serif CJK JP:style=Regular
/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc: Noto Serif CJK KR:style=Regular
/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf: Droid Sans Fallback:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans Mono CJK TC:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans Mono CJK SC:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans Mono CJK KR:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans Mono CJK HK:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans Mono CJK JP:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans Mono CJK SC:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans Mono CJK TC:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans Mono CJK HK:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans Mono CJK KR:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans Mono CJK JP:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans CJK JP:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans CJK KR:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans CJK HK:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans CJK TC:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans CJK SC:style=Bold
where i chose render_font(text = "Noto Sans Mono CJK SC")
from, the way as pointed out in[40].
4.10 Units
For units, there’s the package siunitx that only works for PDF output. As it does some automation i like to use it. It keeps the spacing between the scalar and its unit smaller than around it. However, there’s no working implementation for MathJax that translates between LATEX and HyperText Markup Language (HTML).
The examples (15-22) show how to use a quantity consisting out of a scalar and unit.
\qty{5}{\percent} \ce{K2Cr2O7}
\qty{120}{\degree}
\qty{40.5}{\cm}.
.
\qty{1}{\ml}.
.
\qty{14417}{\Hz}.
.
Kuusnurkset alfat saab konverteerida mehhaaniliselt beetaks ja beeta taastub alfaks, kui seda kuumutada kõrgemal temperatuuril kui $\qty{1273,15}{\K}$.
Kuusnurkset alfat saab konverteerida mehhaaniliselt beetaks ja beeta taastub alfaks, kui seda kuumutada kõrgemal temperatuuril kui \qty1273,15\K.
Lisasime katseklaasi ~$\qty{0,05}{\g}$ lahustatavat ainet (spaatli/pipeti otsatäis).
Lisasime katseklaasi ~\qty0,05\g lahustatavat ainet (spaatli/pipeti otsatäis).
Miks katsetes 3.4 ja 3.5 lahuse värvus ei muutunud (vähemalt $\qty{1}{\min}$ kestel)?
Miks katsetes 3.4 ja 3.5 lahuse värvus ei muutunud (vähemalt \qty1min kestel)?
The example (23) shows additionally how to display just a scalar.
Juhendis on esitatud, et selle aine molaarne ekstinktsioonitegur lainepikkuse $\qty{330}{\nm}$ juures on $\num{34300}$.
Juhendis on esitatud, et selle aine molaarne ekstinktsioonitegur lainepikkuse \qty{330}{\nm} juures on \num{34300}.
The example (24) shows how to show the quantity the qualitative way.
\num{5}-\unit{\percent} \ce{CuSO4} lahust.
- lahust.
The example (25) shows how to use a numeric product as a measurement.
Minu näites tahan ma teada kataloogis *~/eclipse-workspace/test2* asuva faili *children-computers.jpg* omadusi. Näeme, et selle faili tihedus on $\numproduct{96 x 96}$ dpi ja mõõdud on $\numproduct{668 x 371}$ px.
Minu näites tahan ma teada kataloogis ~/eclipse-workspace/test2 asuva faili children-computers.jpg omadusi. Näeme, et selle faili tihedus on \numproduct{96 x 96} dpi ja mõõdud on \numproduct{668 x 371} px.
The examples (26-27) show (additionally) how to use a quantity range.
Standardtasu, kui pole ahvatlevamat ettepanekut, on $\num{40} \frac{\epsilon}{\unit{\hour}}$ ja tavaliselt tegutseme $\qty{1.5}{\hour}$ järjest tehes iga tund $\qtyrange{5}{15}{\min}$ silmadele ja mõistusele pause.
Standardtasu, kui pole ahvatlevamat ettepanekut, on \num{40} \frac{\epsilon}{\unit{\hour}} ja tavaliselt tegutseme \qty{1.5}{\hour} järjest tehes iga tund \qtyrange{5}{15}{\min} silmadele ja mõistusele pause.
Alkoholi olemasolu puhul muutub kroomisegu oranž värvus $\qtyrange{2}{3}{\second}$ kestel roheliseks.
Alkoholi olemasolu puhul muutub kroomisegu oranž värvus \qtyrange{2}{3}{\second} kestel roheliseks.
Some units have subunits on different floors (examples (28-30)).
\unit{\mole\per\cubic\meter}.
\unit{\kg\per\mol}.
õpetaja siiski ütles, et ühik oli hoopis $\unit{\l\per\mol\per\cm}$.
.
.
õpetaja siiski ütles, et ühik oli hoopis \unit{\l\per\mol\per\cm}.
The example (31) additionally shows how to incorporate measurement uncertainty.
$\qty{56,08 \pm 0,07}{\degreeCelsius}$.
\qty{56,08 \pm 0,07}{\degreeCelsius}.
For including R’s values for qty
, they need to be converted into characters as shown in the example (32).
-
Valguse kiirus vaakumis[41(p. 127)].
Some quantities are not present in siunitx
, for instance the short for year in Estonian - “a”.
The example (33) shows how the decimal point if the unit is and it is the smallest unit is not retained[42].
- Pean valmistama vesilahust, mis sisaldab massiprotsenti .
Pean valmistama vesilahust, mis sisaldab massiprotsenti .
The example (34) shows how to retain the decimal point if the unit is and it is the smallest unit.
- Pean valmistama vesilahust, mis sisaldab massiprotsenti .
Pean valmistama vesilahust, mis sisaldab massiprotsenti .
4.11 Equations
4.11.1 Introduction
Equations can be used in math mode, id est either between $
or \[
and \]
. i prefer the bug signs.
4.11.5 Vector
For one-letter-vectors:
\vec{F}
For multiple-letter-vectors:
\overrightarrow{\frac{E \cdot Q}{\mathrm{d}(s)}}
4.11.6 Multiplication
i like to use the dot for a comma. If there are decimals inside the equation according to rules of System Internationale des Unités cross must be used instead of dot:
C_i \times (t + 273.15)^{i - 9}
Otherwise, a center dot is a better solution as cross symbolises vector multiplication as well:
m \cdot \vec{a}
4.11.7 Fraction
\frac
regulates the height of the expression, so that an inline expression has the height of the text line and a block expression has a higher height[43, lk 122]. \tfrac
always renders the expression to have the height of the inline text. \dfrac
always renders the expression to have a higher and better readable height. The examples can be seen in the code block ?? on the page .
4.11.10 Aligning
It’s reasonable to align all the tables:
\begin{align} # 1
\frac{R_{sisemine}}{(R + R_{sisemine})^2} &= 0, R \nequal R_{sisemine} (\#eq:extrema-of-eta-R-initial)\leavevmode\\ # 2
R_{sisemine} &= 0 # 3
(\#eq:extrema-of-eta-R) # 4
\end{align} # 5
# 6
Here, \\
and line break means a real line break.
Additional labels must be placed in the end of the corresponding row just before the double slashes before the line break. Additional labels are displayed on the web page however not linked.
Referencing an equation is also visible in the equation (4.2):
Empty lines aren’t allowed.
4.11.12 Cancelling
\begin{align} # 1
`r if (knitr::is_html_output()) { "\\require{cancel}" }`\frac{\frac{\mathrm{\frac{L^2 \cdot \cancel{M}}{T^2}}}{\mathrm{\cancel{N}} \cdot \Theta}}{\mathrm{\frac{\cancel{M}}{\cancel{N}}}} = \frac{\mathrm{L^2}}{\mathrm{T^2} \cdot \Theta}, # 2
(\#eq:dimensional-analysis-for-specific-gas-constant) # 3
\end{align} # 4
# 5
4.11.13 Underbrace
\underbrace{c_p \cdot (T_\text{out} - T_\text{d})}_{\text{mõistlik soojuskadu õhus}}
4.11.18 Matrices
Avaldisena (4.5) leheküljel on esitatud kolme vektori ristkorrutis[25(lk A-7)],[44].
\begin{align} \vec{V_1} \times (\vec{V_2} \times \vec{V_3}) = \vec{V_1} \times \begin{vmatrix} \vec{i}&\vec{j}&\vec{k}\leavevmode\\ V_{2; x}&V_{2; y}&V_{2; z}\leavevmode\\ V_{3; x}&V_{3; y}&V_{3; z} \end{vmatrix} \tag{4.5} \end{align}
4.12 Text
4.12.1 Non-breaking space
Without a non-breaking space:
Joonistan Lewise skeemi, millele on märgitud ainult elektronid, mitte elemendi sümbol.
With a non-breaking space[45]:
Joonistan Lewise skeemi, millele on märgitud ainult elektronid, mitte elemendi\nobreakspace{}sümbol. # 1
# 2
Joonistan Lewise skeemi, millele on märgitud ainult elektronid, mitte elemendisümbol.
4.12.4 Typewriter
Inline code can be written using \texttt
as seen in the code block ?? on the page[33, lk 23].
4.12.5 Code blocks
Code blocks can be written using the package listings
[46] that can be configured in preamble.tex as seen in the listing ?? on the page .
An example with listings
is shown in the listing ?? on the page .
4.12.6 Line breaks
An example of how to force a line break is shown in the listing ?? on the page[31, lk 271].
4.12.7 Symbols
The examples (35-36) show how to use some symbols as text[47(lk 186)]. The package fontawesome5 is needed for them.
\faHandPointRight
\faHandPointDown
4.13 Chemistry
4.13.1 Chemical symbols
For using the package mhchem, it has to be installed[49]:
After that, mchem can be used:
\require{mhchem}\ce{N_2}
Puidu ja arheoloogiliste proovide dateerimiseks kasutatakse $\ce{^{14}C}$'d, mille poolestusaeg on 5715 a. # 1
# 2
Puidu ja arheoloogiliste proovide dateerimiseks kasutatakse \ce{^{14}C}’d, mille poolestusaeg on 5715 a.
The use with an arrow is shown in the equation
\begin{align} # 1
\color{green}{5}\ce{Na}\color{green}{\ce{Cl}}\ce{O2} + \color{blue}{4}\ce{H}\color{blue}{\ce{Cl}} \ce{->}\leavevmode\\ # 2
\color{blue}{\ce{4Cl}}\ce{O2} + \color{green}{5}\ce{Na}\color{green}{\ce{Cl}} + \ce{2H2O} # 3
(\#eq:ce-with-arrow) # 4
\end{align} # 5
# 6
\begin{align} \color{green}{5}\ce{Na}\color{green}{\ce{Cl}}\ce{O2} + \color{blue}{4}\ce{H}\color{blue}{\ce{Cl}} \ce{->}\leavevmode\\ \color{blue}{\ce{4Cl}}\ce{O2} + \color{green}{5}\ce{Na}\color{green}{\ce{Cl}} + \ce{2H2O} \tag{4.6} \end{align}
Aldehüüd on redutseerija ja redutseerib komplekseeritud vask(II)iooni # 1
vask(I)oksiidiks: # 2
# 3
$$\ce{2Cu^2+}_\text{complexed}\ce{+2[OH]- + 2e- -> Cu2O + H2O}.$$ # 4
# 5
Aldehüüd on redutseerija ja redutseerib komplekseeritud vask(II)iooni vask(I)oksiidiks:
\ce{2Cu^2+}_\text{complexed}\ce{+2OH- + 2e- -> Cu2O + H2O}.
4.13.2 Electron configuration
For automatically displaying electron configuration, one can use the package elements[50].
Electron configuration for carbon which is the sixth element in the periodic system of chemical elements:
4.13.3 Orbital energy level diagram
For generating orbital energy level diagrams, one can use the package modiagram[51]. It only works up to the second energy level.
This is how to display an orbital energy levels diagram for carbon:
# 1
\begin{modiagram}[style = square, labels] # 2
\atom{left}{1s, 2s, 2p = {; up, up}} # 3
\EnergyAxis[title] # 4
\end{modiagram} # 5
# 6
It’s still possible to hack in the third levels’ s- and p-levels but not further levels as seen for sulfur:
4.13.4 Lewis dot diagram
For generating Lewis dot diagrams, one can use the package chemfig[52].
This is how to display the Lewis dot diagram for sulfur using angles:
4.13.5 Molecular schemas
chemfig is useful for drawing molecular schemas as seen in the schema (4.7) on the page .
\begin{align} # 1
\chemfig{ # 2
H-[:30] # 3
O-[:-30] # 4
-[:30](-[:90]O-[:150]H) # 5
-[:-30](=[:-90]O) # 6
-[:30] # 7
O(-[:90]H) # 8
-[:-30,,,,dash pattern=on 1pt off 1pt] # 9
Cu-[:30,,,,dash pattern=on 1pt off 1pt] # 10
O(-[:90]H) # 11
-[:-30](=[:-90]O) # 12
-[:30](-[:90]O-[:30]H) # 13
-[:-30] # 14
-[:30] # 15
O-[:-30] # 16
H # 17
} # 18
(\#eq:copper-glycerate) # 19
\end{align} # 20
# 21
[@pubchem_copper]. # 22
# 23
[53].
A more complicated molecular diagram is represented as the schema (4.8) on the page .
\begin{align} # 1
\chemfig{ # 2
\underbrace{\chemfig{H-[:180]O-[:180]-[:-90](-[:-90]-O(-[:30,,,,dash pattern=on 1pt off 1pt])-[:-90]H)-O-[:-30]Cu-[:-30]O-(-[:90]-[:180]O(-[:-150,,,,dash pattern=on 1pt off 1pt])-[:90]H)-[:-90]-[:180]O-[:180]H}}_\text{vask(II)glütseraat}. # 3
(\#eq:Cu-II-glycerate) # 4
\end{align} # 5
# 6
Vesi ja hüdroksübenseen (fenool [@haynes_2014_crc, p. 3-446], $\chemfig{*6(-=-=(-OH)-=)}\qquad$ [@haynes_2014_crc, p. 3-447], tsükloalkeen) omavahel ei lahustu, sest hüdrofoobseid süsinikke on võrdlemisi palju. # 1
# 2
Vesi ja hüdroksübenseen (fenool[25(pp. 3–446)], \chemfig{*6(-=-=(-OH)-=)}\qquad[25(pp. 3–447)], tsükloalkeen) omavahel ei lahustu, sest hüdrofoobseid süsinikke on võrdlemisi palju.
1,3-benseendiool ($\chemfig{*6(-=(-\ce{OH})-=(-\ce{OH})-=)}$, resortsiin `r render_with_emojis(text = "(ref:haynes-2014-crc), p. 3-480")`). # 1
# 2
1,3-benseendiool (\chemfig{*6(-=(-\ce{OH})-=(-\ce{OH})-=)}, resortsiin[25(pp. 3–480)]).
Hüdroksübenseen reageeris raudkloriidiga niimoodi: # 1
# 2
$$\ce{3} \chemfig{*6(-=-=(-\ce{OH})-=)} \ce{+ FeCl3 ->} # 3
\chemfig{ # 4
*6(-=-(-O-[:30]Fe(-[:90]O(-[:90]*6(-=-=-=)))-[:-30]O-[:-30]*6(-=-=-=))=-=) # 5
} # 6
\ce{+ 3HCl}.$$ # 7
# 8
Hüdroksübenseen reageeris raudkloriidiga niimoodi:
\ce{3} \chemfig{*6(-=-=(-\ce{OH})-=)} \ce{+ FeCl3 ->} \chemfig{ *6(-=-(-O-[:30]Fe(-[:90]O(-[:90]*6(-=-=-=)))-[:-30]O-[:-30]*6(-=-=-=))=-=) } \ce{+ 3HCl}.
4.14 Physics
Current diagrams are only shown in the print form. For a current diagram, i need to add the following line into preamble.tex:
# 1
\begin{figure} # 2
\begin{circuitikz}[european] # 3
\draw # 4
(0, 0) to[dcvsource, l = $E$, v_ = $r$] (0, 2) # 5
to[ammeter] (2, 2) # 6
to[vR, l = $R$, *-*] (2, 0) -- (0, 0); # 7
\draw # 8
(2, 2) to[voltmeter] (4, 2) -- (4, 0) -- (2, 0) # 9
; # 10
\end{circuitikz} # 11
\caption{Skeem, mille järgi toimetasime.} \label{fig:schema} # 12
\end{figure} # 13
# 14
4.15 New page
The following snippet is the code for a page break:
If the new page must be empty then the following code snippet is useful:
4.16 Blanks
For scaffolding, one needs to have these rows in preamble.tex[54]:
% for fill-in-the-gaps-tests # 1
\newlength{\blankwidth} # 2
\newcommand{\blank}[1]{% # 3
\ifmmode\settowidth{\blankwidth}{\ensuremath{{#1}{#1}{#1}}}% # 4
\else\settowidth{\blankwidth}{{#1}{#1}{#1}}% # 5
\fi # 6
\makebox[\blankwidth]{\dotfill}} # 7
# 8
Then, you can use blank
:
The output looks like:
Täna on 2023-12-12 ja mina olen .