This post is experimenting with the HTML syntax.
section
The quick brown fox.
1 section
1.1 subsection
2 section
This post is experimenting with the HTML syntax.
The quick brown fox.
The short summary is, that Lyx is the most advanced typesetting software. The details why this makes sense is given next.
The perhaps obvious attempt to create a text is a text editor, for example gedit. The problem with plain text editors is that they are not able to handle images and tables which are both needed for creating pdf documents. So the question is, how to create such complex documents? There is more than a single option for doing so:
- latex
- libreoffice, abiword
- HTML
- pandoc
All these options have advantages and disadvantages. Typeseeting is a complex domain and many books and papers were written about it. The reason why latex outperforms all the other software packages is not because of the software itself, but because of the communit yaround it. If someone enters in a search engine of choice a typographic related question he can be sure, that this question was discussed already in a tex related content. That means the tex community is the largest typographic oriented community in the internet.
In theory it is possible to format a document with abiword or HTML. From a technical perspective both programs are well suited for the job. The abiword software is a lightweight program which supports twocolumn mode, can generate pdf files and has access to all the build in fonts. Also the HTML language is well suited for created documents. The largest HTML standard supports hyphenation, justified text and of course PNG images. Or let me explain it a bit more direct. A bad formatted latex document and a well formatted abiword document are looking nearly the same.
In the latex community there is a single tool available which has a unique position: lyx. In contrast to all the other frontends like Scientific word, texmaker or emacs, lyx combines many features. It allows to create easily complex documents and the main strength is perhaps the ability to insert linked images plus the outline window. So lyx has much in common with an outline editor but it is producing TeX quality documents.
The famous typesetting system from knuth was mentioned already. The reason why this program is used frequently is because the ability to produce justified text. Perhaps it makes sense to explain this feature in detail. Information in the internet are usually displayed in a sans serif font with left justified paragraphs. This is the most efficient way to present text on low resolution monitors. Sans serif fonts are easier to read, and left justified text makes it easier for a browser to reformat the content if the size of the windows is changed.
In contrast printed text needs a different format. The common standard for printed documents is to use a serif font in combination with a fully justified paragraph. Creating fully justified paragrpahs is more complex because the change is high that longer white spaces are visible. To prevent these white gaps, TeX is using the Knuth Plass line wrapping algoirthm. Tex and Adobe Indesign are the only programs available which are able to do so.
MS-Word, Abiword, libreoffice writer and HTML are not using a global optimization technique and the result is, that the justified paragraphs has a lower quality. In theory there are some github repositories available with the aim to implement knuth plass line breaking algoirthm in the HTML rendering engine. But until now this isn't possible. So we can say that from an objective standpoint, tex is the most advanced typesetting software available and has the largest community. So it is a here to stay if someone likes to create documents with a computer.
The best way in figuring out what TeX is can be realized by deactivating all the advantages of TeX. The idea is to produce documents in the same quality like MS-Word is able to realize. From a technical perspective this is realized with the following commands in the preamble:
\usepackage{times}
\usepackage[none]{hyphenat}
\sloppy
\setlength{\parskip}{1pt}
\setlength{\topskip}{0pt}
These commands are activating the Times font, deactivating the hyphenation, switch off the inter word spacing optimization and deactivating the vertical space optimization. The resulting text will have lots of white gaps in the text and the paragraphs are positioned as they are on the page.
The interesting situation is, that such a setting is not recommended but the output looks ok. That means, graphics and text can be read easily and the only thing which is missing is the additional 1% of typographic quality provided by the TeX engine. If in addition a Times fonts was used the difference to an Abiword generated document is very low.
There is an interesting upcoming github project available under the URL https://github.com/mandolyte/mdtopdf which has to do with converting a markdown file into the pdf format.
Somebody may argue that such a converter is already available and it is built in into the pandoc tool. But, pandoc is using the external latex program while the previously mentioned tool was written in go and doesn't need TeX at all. There is a reason why such tool wasn't available in the decades before, because the subject is difficult to understand.
On the first look a markdown to pdf converter has to do with converting format A into format B. But a closer look towards the problem will show that it more complicated. The markdown format is similar to HTML a markup language. It contains of text which is enriched with additional information. In contrast, a printer and the printer format PDF doesn't contain of text but it is action oriented. And this makes it harder to write a converter.
Basically spoken, the pdf format is not a text format similar to a .html but it is printer command language. It contains of actions like "drawtext()". So the converter has to read a plain text file as input and generates a script which is executed on the printer as output. So it is a text to program converter. And this makes it hard to write such a converter.
Let us give an example. In the markdown syntax a bold formatting is realized by "**hello**". This is a typical example for a markup syntax. The text author writes something and then the word should be printed. But, a printer doesn't work in this way. A printer doesn't need content but a command. What a printer can execute is a command like:
setfont(bold)
drawtext("hello")
That means, the original markdown file holds textual information, while the printer API is working with action commands. Or let me explain it the other way around. A markdown file can't be executed on a shell because it contains no commands, while a printer command language script doesn't holds information but it contains of statements.
There are endless amount of software available which are promising to create high quality pdf documents. Some of them can be used in reality while other have become obsolete. The main problem is not how to program these tools but the bottleneck is to understand what word processing is in general.
A common assumption is that there are two different approaches available namely WYSIWYG programs and markup oriented tools. Software programs for each categories are widely known so there is no need to reference them again. The reason is that typesetting is used by a large amount of users and the PC is well suited for such a purpose.
First thing to do is to understand what the average user is doing with a word processor. In most cases the starting position is a zip file which contains of text files and image files. And the goal is to convert this zip file into a pdf document. The steps in between are realized with the typesetting program.
To understand what the task in between is, we have to focus on the technical needs. The step in between is realized with a printer command language. A printer command language is a programming language used to send commands to a plotting device. And this description is maybe a bit unusual. Because the starting text file is not a program and what the user likes to do is print out this text file. But a printer can't handle plain text files, what a printer is a command file.
In the past, lots of command languages were created. The concrete specification is not important at all. It is even possible to invent a command language for a display. Suppose there is a pixel map on the screen which has 700x300 pixels. A printer command language is used to draw on this screen. It is relatively easy to imagine what the commands are. In the easiest case the printer command language contains of commands like drawtext(x,y,text) and drawimage(x,y,image).
The output device is not a file, similar to a text file on the computer, but the output device is a computer, which accepts commands but not content. Word processing means to convert a zip file which contains of content into a command language which contains of actions. Let me give an example:
# command language example
title="hello world"
drawtext(0,0,title)
abstract="Lorem ipsum"
drawtext(0,20,abstract)
image=screenshot.png
drawimage(0,50,image)
paragraph="lorem ipsum"
drawtext(0,0,paragraph)
This mini program has much in common with a python script but it is printing something to a screen. The interesting situation is such a file doesn't contain of normal text and it is not a markup language, but it is sequence of action words, formulated in a printer command language. Such a script can be executed on a printer or a graphic display. So the question is how to create such a command language script? One option is enter to commands manually, or to use a generator. This would result into a multi step process.
1. input: textfile, images
2. printer command language
3. output: pdf file
Generating a pdf paper with a command language
The interesting situation, that even the pdf format is known since years and around 100 different programs are available to create such a file format, it remains unclear what exactly word processing is about. The reason is, that the subject is mostly defined from a users perspective which makes it hard to grasp the underlying technical pipeline.
From a users perspective there are two sorts of programs available: WYSWYG programs and markup languages. Instead of arguing which of these tools are working better the idea is to describe in general what typesetting and printing is about. Typesetting means to convert content into commands. An example for content is a text file or a png image. And an example for a printer command is "drawtext()".
So what is the difference? It has to do with different understanding of the same subject. An author of a text things in categories of content. He writes a text or he draws an image. All these content is stored in files. A text file contains of information but it can't be executed. In contrast, an output device like a printer or a graphic display have a different perspective to the world. They are operating with commands. That means, a printer provides to the outside world a API (application programing interface). Printing something out means to translate between content into commands. This is inbetween step is realized by word processor.
After this introduction let us take a low how to print out something from a low level perspective. The idea is, that not the content stands in the focus but the needs of the output device. In the concrete case the output device is a pdf file which is created by the FPDF libray in the python language.
import fpdf,os
width=190
pdf = fpdf.FPDF()
pdf.add_page()
title="lorem ipsum"
pdf.set_font('Arial', '', 32)
pdf.multi_cell(width,12,title,1,"C")
pdf.ln()
text="""Longer text
newline
lorem ipsum."""
pdf.set_font('Arial', '', 12)
pdf.multi_cell(width,6,text,1,"J")
pdf.ln()
pdf.output('1.pdf', 'F')
os.system("evince 1.pdf")
After running this Python script it will create a pdf file and show it on the screen. The interesting situation is, that the python script contains of commands. That means, the printer doesn't understand a text file but it needs a commands to print a certain line. Suppose the idea is to print out a longer document which has 20 pages. This is realized by providing lots of commands after each other. At the beginning there is a command for printing the headline, then a command for the abstract, then a command for a picture and so on.
The problem is, that most authors are not trained to formulate a text in this way. The author doesn't like to program a printer, but he likes to print a text file. So the question is how to convert a ".txt" file into a ".py" script which contains of printer commands? This is indeed an interesting problem and it is handled by word processing software. A word processor takes content from the user and converts it into a command language.
In theory it is possible to convert the markdown format into a printer command language. Such a tool would work the following way. The text author writes something into th markdown format which is a plain text format. Then the converter is started. The converter takes the markdown content and generates a python script formulated in the printer command language. The python script contains the syntax of the fpdf library which is mostly the command multi_cell() and set_font(). These commands are send to the virtual printer and are generating the pdf file.
The challenge is to convert the markdown content into an action language. For example in the markdown syntax a new section is started with "## section". But this markup syntax contains only of content but it is not a command. A command which can be interpreted from a printer would look like:
pdf.set_font('Arial', '', 12)
There is a typical communiation problem. The author of a text things in categories of content, while the output printer needs dedicated commands to operate. The interesting situation is, that with the correct commands the printer device can do anything. That means, it will output a single character or a longer text line. The only problem is how to convert content into action.