You probably know that using a good data structure can dramatically improve an algorithm
And you use structured programs
The same applies to structuring our documents
Maybe you have used LaTeX, or Markdown
Maybe you know HTML
Separate style from structure
Describe the role of text, not the “looks”
The key idea is to describe what things are, not how they look
This part is based on the ideas discussed in “LaTeX: A Document Preparation System” by Leslie Lamport (1986).
Structure makes the house solid and comfortable
If you only do decoration, the house looks nice but it is not solid
Structure of the walls come first
Painting the walls in a nice color is secondary
The first tool we learn today is a WYSIWYG word processor
In word processors like Word®,
What You See Is What You Get
This is sometimes called WYSIWYG
It is easy to change fonts, sizes, colors and other visual attributes, without paying attention to structure
You can follow the same philosophy:
Separate style from structure
Focus on content
Mechanical typewriters were invented in 1874
They had only one font
We still use the same keyboard
Since there was only one type of letter, people used some symbols as “magic”
For example \
or @
If you write a “magic” symbol, you tell the computer that the next symbol shows a change of format
This is called Markup Language
An important system to prepare documents in the computer was invented in the 70’s by Donald Knuth, who is probably the most important computer scientist of the last 70 years.
Donald Knuth won the Turing Award in 1974
TeX has styles but not structure. In the 80’s Leslie Lamport created LaTeX as an extension of TeX
Leslie Lamport won the Turing Award in 2013
A LaTeX document looks like this
\documentclass[a4paper]{article}
\title{Ten Simple Rules for Online Learning}
\author{David B. Searls}
\date{13 September 2012}
\begin{document}
\section{Rule 1: Make a Plan}
There are many possible motivations for becoming involved in online learning…
\end{document}
LaTeX files are text files. They will never be obsolete.
Changing the documentclass
will change the document
look
It is free
it forces you to think logically and organize your ideas
Write first, compile later
Do not waste time playing with fonts
Good journals accept LaTeX submissions
(they also accept Microsoft Word format)
Independent of any provider
Use your favorite text editor (VScode?)
Version control friendly (GitHub?)
Can probably still be read 20 years from now
We cannot say the same about Microsoft Word
The main mistake that people should stop making is
Worrying too much about formatting and not enough about content.
“How (La)TeX changed the face of Mathematics”. An E-interview with Leslie Lamport. http://lamport.azurewebsites.net/pubs/lamport-latex-interview.pdf
After writing your paper, you will probably present it
(or maybe before finishing it)
Using structured document makes it easy to recycle your material to presentation slides
In LaTeX you can do that using the beamer
document
class
LaTeX is favored by people who writes mathematical formulas
\[(a+b)^n=\sum_{k=0}^n \frac{n!}{k!(n-k)!} a^k b^{n-k}\]
You can use this syntax in Microsoft Word’s Equation Editor
Learning how to write math is a good investment
There are hundreds of citation styles
Life is too short to sort references manually
LaTeX also provides a convenient way to handle references
References are stored in a separate text file, in BiBTeX format
Many tools can create BiBTeX files for you
In the 90’s most computers had good graphic capabilities and Internet access
Researchers at CERN invented the web, using “hyper-text”
(That is, text with links to other text)
Web pages are written in Hyper Text Markup Language
These are also text files. It looks like this:
Works well on the screen: adapts to screen size
Links to other pages
Structural elements
<h1>…</h1>
marks Header level 1<h2>
…<h6>
Comments:
<!-- this part is not shown -->
Structure separated from Style
It does not work well for paper
It is hard to write manually
There are editors, but they often focus on style, not structure
It is a light markup system that can be easily converted into nice presentations
The easiest way to handle text files is to use a text editor
These are programs to view and edit text files
They use a monospaced font, like Courier
Each letter has the same width
Since each letter has the same size, text editor use color
The color depends on the role of each text
For example, headings can be in red color
The color is not in the file. The editor puts colors
These work with Markdown and other formats
code.visualstudio.com
rstudio.com/products/rstudio/download/
All are good. We use VSCode
stackedit.io
dillinger.io
draftin.com
jbt.github.io/markdown-editor/
Free
nothing to pay
you can do whatever you want
Never get obsolete
We want to identify the meaning, not the shapes
The key idea is to describe what things are, not how they look
Describe the role of text, not the “looks”
Separate style from structure
There are several markup languages that encode the structure of a text document
Markdown is a widely used markup language
Same philosophy as LaTeX, but simpler
The text file can be read and understood easily
It can be transformed into other formats
Used in R, Python, Julia (Jupyter), in GitHub, and many other modern platforms
“The overriding design goal for Markdown’s formatting syntax is to make it as readable as possible.
“The idea is that a Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions.”
John Gruber https://daringfireball.net/projects/markdown/
Compiling is transforming from Markdown to other format
There are many different Markdown compilers
Many people make their own compiler, and they expand the original idea
Unfortunately, they are not always 100% compatible
There is not yet an official standard
Recommendation: pandoc
(if you have RStudio, you have Pandoc)
If you need to convert files from one markup format into another, pandoc is your swiss-army knife
John MacFarlane, developer of Pandoc
Pandoc can convert between many formats, including
Professor of Philosophy, University of California, Berkeley
Author of books
Recent papers:
Text files
It is easy to write tables in Markdown
It is easy to write lists
Can be used for slides
Handles BiBTeX references
It is a command line command, and can be used inside VSCode
There is even a plugin
In the command line we write
and there are many options. See https://pandoc.org
The first paragraph.
Another paragraph
The first paragraph.
Another paragraph
# Header 1
## Header 2
### Header 3
#### Header 4
Header 1
Header 2
Header 3
Header 4
+ Item 1
+ Item 2
+ Item 2a
+ Item 2b
- Item 1
- Item 2
- Item 2a
- Item 2b
Sub-lists are indented by 4 spaces
1. Item 1
1. Item 2
1. Item 3
1. Item 3a
1. Item 3b
- Item 1
- Item 2
- Item 3
- Item 3a
- Item 3b
You have to indicate the web address of the image
![optional text](http://example.com/logo.png)
or the name of a file in the same directory
![optional text](images/logo.png)
![optional text](images/logo.pn)
There are several formats. The easiest one is this
| | sample | dose | time | agent |
|---|----------|------|-------|------------------|
| 1 | GSM91440 | low | 5 min | caffeine |
| 2 | GSM91893 | low | 5 min | caffeine |
| 3 | GSM91428 | low | 5 min | calcofluor white |
| 4 | GSM91881 | low | 5 min | calcofluor white |
sample | dose | time | agent | |
---|---|---|---|---|
1 | GSM91440 | low | 5 min | caffeine |
2 | GSM91893 | low | 5 min | caffeine |
3 | GSM91428 | low | 5 min | calcofluor white |
4 | GSM91881 | low | 5 min | calcofluor white |
There are some VSCode plug-ins that can make tables for you
Or you can make them in R using knitr
or
pander
libraries
A good alternative is this website:
Programs are usually written in a monospaced font.
That is, all letters have the same width.
```
this <- is.computer(code) {
# comment
}
```
this <- is.computer(code) {
# comment
}
You can indicate the language, and get colors
```r
this <- is.computer(code) {
# comment
}
```
To write a reference for a web page
This is a [clickable text](https://dry-lab.org/).
This is a clickable text.
It can also be written in [a cleaner format].
[a cleaner format]: http://dry-lab.org
It can also be written in a cleaner format.
The link address can given in a separate line
Here is a footnote reference,[^1] and another.[^longnote]
[^1]: Here is the footnote.
[^longnote]: Here's one with multiple blocks.
Subsequent paragraphs are indented to show that they
belong to the previous footnote.
This paragraph won't be part of the note, because it
isn't indented.
Here is a footnote reference,1 and another.2
This paragraph won’t be part of the note, because it isn’t indented.
We can compare `x` and `data`
We can compare
x
anddata
Use it only when strictly necessary
Inside the paragraph we can have *italics*
and **bold** text
Inside the paragraph we can have italics and bold text
For your weekend
Comments in Pandoc
Pandoc can understand some HTML
If we wite an HTML comment, it will not show in the output
(Must use pandoc option
--strip-comments
)