-
Notifications
You must be signed in to change notification settings - Fork 0
/
latex
450 lines (336 loc) · 10.8 KB
/
latex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# To insert a table of contents
A table of contents (ToC) is produced by inserting \tableofcontents at the appropriate place in your document.
# To get a partial derivative in latex
\partial
# symbols
# angstrom in text mode
\AA
# To insert a close enough degree symbol in latex
$^{\circ}$
# math symbols
\mp for +-
\equiv for equivalent
# tilde
\sim
# infinity
\infty
# square root
\sqrt{things under root}
# not equal
\neq
# plus or minu
\pm
# hat or cap
\hat{a}
# arcsec
\arcsec # this comes from some package
# in math mode you can just use '' and this will translate to the arcsec symbol
# latex transpose
\mathbf{A}^T
# norm
|| x ||
# elbow symbol for logical negation
\neg
# set intersection symbol
\cap
# Correct way when running biber
pdflatex test
biber test
pdflatex test
# For your compilation to work properly, you should compile in the following manner:
pdflatex file.tex && bibtex file.aux && pdflatex file.tex && pdflatex file.tex
# generate fake text with the blindtext package
\blindtext
# define a path for images
\graphicspath{ {./images/} }
# To avoid numbering sections but make them appear in toc
\setcounter{secnumdepth}{0}
# link style set up
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan,
}
# squiggly underline
\usepackage[normalem]{ulem} % [normalem] to set \emph{} to default behaviour (italic instead of underlining)
...
\uwave{to be underlined in a squiggly way}
# spacing
\usepackage{setspace}
\onehalfspacing
# changing fonts
{\tt This will be in a "typewriter font"}
# add space after line breaks
\\[3cm]
# insert photo in a resume
\begin{tikzpicture}[remember picture, overlay]
\node [anchor=north east, inner sep=0pt] at (current page.north east)
{\includegraphics[height=3cm]{example-image}};
\end{tikzpicture}
# suppress page numbering
\thispagestyle{empty}
# insert tabular
\begin{tabular}{lr}
a & b \\
c & d \\
\end{tabular}
# inserting degree symbol
# The \degree command is provided by the gensymb package
\usepackage{gensymb}
# create outline or bookmarks automatically
\usepackage[bookmarks]{hyperref}
# break urls
\usepackage[breaklinks=true]{hyperref}
# using natbib package
# cite within paranthesis
\citep
# use natbib to cite only author
\citeauthor
# in text citations
\citet
# including images
# relative path of images should be relative to the main .tex file
# cross referencing when using external files
\usepackage{xr}
% In your preamble
\myexternaldocument{File2}
# referencing a section
Use \label{} next to a section and then \ref{} to create the reference.
# display a wide figure in a two column document
\begin{figure*}
# for \toprule \midrule etc
\usepackage{booktabs}
# blank to fill in latex
\rule{1cm}{0.5mm}
# color text differently
# requires the xcolor package
\textcolor{red}{what ever}
# enclosing paranthesis
\left( \right)
\left[ \right]
# underline a character
\underline{u}
# add a footnote
\footnote{text for footnote}
# insert image as grid
\begin{figure}
\begin{tabular}{cc}
\includegraphics[width=65mm]{it} & \includegraphics[width=65mm]{it} \\
(a) first & (b) second \\[6pt]
\includegraphics[width=65mm]{it} & \includegraphics[width=65mm]{it} \\
(c) third & (d) fourth \\[6pt]
\multicolumn{2}{c}{\includegraphics[width=65mm]{it} }\\
\multicolumn{2}{c}{(e) fifth}
\end{tabular}
\end{figure}
# resize table width
\resizebox{\columnwidth}{!}{%
\begin{tabular}{r|lll}
\multicolumn{1}{r}{}
& \multicolumn{1}{l}{Heading 1}
& \multicolumn{1}{l}{Heading 2}
& \multicolumn{1}{l}{Heading 3} \\ \cline{2-4}
Row 1 & Cell 1,1 & Cell 1,2 & Cell 1,3 \\
Row 2 & Cell 2,1 & Cell 2,2 & Cell 2,3
\end{tabular}%
}
# include cpp
C\texttt{++}
# put citation inside caption
\protect \cite{citekey}
# cannot find reference error can occur if \label comes before \caption in figure environment
# combined multiple input files to single latex file
latexpand main.tex > combined.tex
# keep comment
latexpand --keep-comments main.tex
# bibliography
\begin{thebibliography}{9} % Replace "9" with the maximum number of digits in your citations
\bibitem{chollet2018}
Chollet, François. \emph{Deep Learning with Python}. Shelter Island, New York: Manning Publications Co, 2018.
% Add more \bibitem entries if needed
\end{thebibliography}
When you compile your document, the \cite command in the text will generate a citation number within square brackets, and the bibliography section will display the manually entered bibliography entries.
Note that this approach requires you to manually maintain the bibliography entries within the LaTeX document. If you have a large number of references or plan to reuse them in multiple documents, using a separate .bib file with BibTeX is generally more convenient.
# multi line comments in overleaf
ctrl + /
# insert text into equation
\textrm{your text here}
# convert tex to epub
# use fixed width for images to render well in epub output
tex4ebook main.tex
# Use pdflatex without interactive prompts
-interaction=nonstopmode
# Mark the differences between two pdf versions on the updated pdf using
# the corresponding tex files
# https://www.overleaf.com/learn/latex/Articles/Using_Latexdiff_For_Marking_Changes_To_Tex_Documents
latexdiff old_version.tex new_version.tex > diff.tex
pdflatex diff.tex
bibtex diff.aux
# To not have lines broken in the diff
latexdiff -t CFONT
# Only Highlight additions in bold
latexdiff -t BOLD last_read.tex main.tex > diff.tex
# table environment
\begin{table}
\end{table}
# Using bib file for creating references
\documentclass{article}
\begin{document}
This is a citation example \cite{einstein1905}.
\bibliographystyle{plain} % Choose a bibliography style
\bibliography{mybibfile} % Name of your .bib file
\end{document}
# citing online resources with bibtex
@misc{winnt,
title = {{ms windows nt} kernel description},
howpublished = {\url{http://web.archive.org/web/20080207010024/http://www.808multimedia.com/winnt/kernel.htm}},
note = {accessed: 2010-09-30}
}
# To keep First Name and Surname as single unit in citation
@book{citekey,
author = {{FirstName LastName}},
}
# If you use \bibitem way of including references, the sequence of 4 commands, pdflatex -> bibtex -> pdflatex etc is not needed.
# To generate \bibitem eventhough you are use a bib file and bibtex after running bibtex copy the contents of the .bbl file
# Use natbib
\usepackage{natbib}
\bibliographystyle{unsrtnat}
# Renew name of bibliography
\renewcommand\bibname{Reference}
\printbibliography[title={Reference}] # Using biblatex
# number items in bibliography
\usepackage[numbers]{natbib}
# cite multiple references
\cite{citation01,citation02,citation03,citation04,citation05}
# for code
\begin{verbatim}
\end{verbatim}
# insert urls
\href{/path/to/link}{display text}
# make a citation like this (DR7; Abazajian et al. 2009)
\citep[DR7;][]{abazajian_seventh_2009}
# basic bibliography
\usepackage{natbib}
\begin{document}
...
\bibliography{zotero.bib}
\bibliographystyle{plain}
\end{document}
# combine figures and tables using subfigure
\usepackage{caption}
\usepackage{subcaption}
The width specified for each subfigure should add upto the textwidth
in each include figure specify width as \textwidth but it will be what you
specified in the subfigure line instead of original \textwidth
\begin{figure}[htb]
\centering
\begin{subfigure}{0.48\linewidth}
\includegraphics[width=\linewidth]{Figures/Linear regression/LinearReg_Fib}
\caption{}
\end{subfigure}
\hfill
\begin{subfigure}{0.48\linewidth}
\includegraphics[width=\linewidth]{Figures/Linear regression/LinearReg_RBC"}
\caption{}
\end{subfigure}
\medskip
\begin{subfigure}{0.48\linewidth}
\includegraphics[width=\linewidth]{Figures/Linear regression/LinearReg_Leuko"}
\caption{}
\end{subfigure}
\hfill
\begin{subfigure}{0.459\linewidth}
\centering
\sisetup{group-four-digits}
\begin{tabular}{l S[table-format=4.1]S[table-format=-3.2] }
\toprule
& C10 & C01 \\
\midrule
F/P low & 240.1 & 171.3 \\
F/P & 763.5 & 269.08 \\
F/P mo & 1201.0 & 190.6 \\
F/P h & 6651.6 & -345.9 \\
\bottomrule
\end{tabular}
\end{subfigure}
\caption{Linear regression model between sample stiffness (determined as the tangent modulus at 75\%) and (a) Fibrin/platelet content, (b) Red blood cells and (c) Leukocytes}
\label{fig:LinearRegression}
\end{figure}
#Clean up (remove) all regeneratable files generated by latex and bibtex or biber. This is the same as the -c option with the addition of dvi, postscript and pdf files, and those specified in the $clean_full_ext configuration variable.
latexmk -C main.tex
# remove comments from document
# https://tex.stackexchange.com/questions/83663/utility-to-strip-comments-from-latex-source
# NOTE that this also makes a single file out of all includes
latexpand --empty-comments mytexfile.tex > mytexfile-stripped.tex
# remove lines with only % and whitespace
sed -i '/^\s*%/d' mytexfile-stripped.tex
# to provide a shorter chapter title that appears in the header
\chapter[<short title>]{<long title>}
# insert equations
\usepackage{amsmath}
\begin{gather} # without alignment on equals
eqn \\
eqn 2
\end{gather}
\begin{align} # align on equals
a &= b
c &= d
\end{align}
# count words appearing in pdf from tex file
texcount filename.tex
# brackets
\left(
\right)
# use trim to crop a figure
\includegraphics[trim={1cm 10cm 1cm 2cm }, clip, width=\textwidth]{figure.pdf}
# place output file in separate directory
pdflatex -output-directory=target <file>
# minimal code need for bibliography using bibtex
\bibliographystyle{plain} % We choose the "plain" reference style
\bibliography{refs} % Entries are in the refs.bib file
# pound symbol in \url is unsupported escape it to avoid errors
# stylised l
$\ell$
# script version of captial letters
\mathcal{A}
# wrap long lines by defining fixed width for columns
\begin{tabular}{|p{5cm}|c|c|}
# right margin
\usepackage[right=3cm]{geometry}
# disable todos from todonotes package
\usepackage[disable]{todonotes}
# remove empty pages after a chapter in book
\documentclass[openany]{book}
# quick verbatim text
\verb|text with special characters \ { }|
# insert text within align environment
\intertext
# break long urls
\usepackage[hyphens]{url}
# foldable block
\documentclass[a4paper]{minimal}
\usepackage{ocgx}
\begin{document}
Max Mustermann \switchocg{ocg1}{\fcolorbox{blue}{red}{\bfseries +}}\begin{ocg}{OCG 1}{ocg1}{0}
\colorbox{yellow}{ \parbox{5cm}{Max Mustermann\\Musterweg 1\\12345 Musterstadt}}
\end{ocg}
Erika Mustermann
\end{document}
# code with line breaks
# Using a monospaced font for the listing fixes most of the copy-paste issues
\usepackage{listings}
\lstset{
breaklines=true, % Prevents breaking lines
basicstyle=\ttfamily % Uses monospaced font
}
\begin{lstlisting}
...
\end{lstlisting}
#
# add to contents or toc
\listoftodos
\addcontentsline{toc}{chapter}{List of Todos}
# strikeout or strikethrough
\usepackage[normalem]{ulem}
\sout{Hello World}