Englanninkielisen tekstin ladonta

Kokeillaan nyt tuottaa hiukan monisanaisempia dokumentteja. Aloitamme englanninkielisellä tekstillä, kun LaTeX oletuksena ymmärtää englannin päälle.

Esimerkkiteksti

Seuraavassa on pätkä Arthur Conan Doylen teoksesta ”The Valley of Fear” (koko kirja on vapaasti saatavilla Project Gutenberg -palvelussa):

“I am inclined to think—” said I.

“I should do so,” Sherlock Holmes remarked impatiently.

I believe that I am one of the most long-suffering of mortals; but I’ll admit that I was annoyed at the sardonic interruption. “Really, Holmes,” said I severely, “you are a little trying at times.”

He was too much absorbed with his own thoughts to give any immediate answer to my remonstrance. He leaned upon his hand, with his untasted breakfast before him, and he stared at the slip of paper which he had just drawn from its envelope. Then he took the envelope itself, held it up to the light, and very carefully studied both the exterior and the flap.

“It is Porlock’s writing,” said he thoughtfully. “I can hardly doubt that it is Porlock’s writing, though I have seen it only twice before. The Greek e with the peculiar top flourish is distinctive. But if it is Porlock, then it must be something of the very first importance.”

He was speaking to himself rather than to me; but my vexation disappeared in the interest which the words awakened.

“Who then is Porlock?” I asked.

Ladonta LaTeXilla

Tämän esimerkkitekstin latominen LaTeXilla on hyvin suoraviivaista. Tekstissä ei esiinny sellaisia erikoismerkkejä kuin \, {, }, & tai $, joilla on LaTeX-dokumentissa erikoismerkitys. Kappaleenvaihdot on jo valmiiksi merkitty tyhjällä rivillä — tämä on LaTeXissakin oikea tapa merkita kappaleenvaihtoa. Voimme siis kirjoittaa yksinkertaisesti tällaisen LaTeX-dokumentin:

\documentclass{article}
\begin{document}
“I am inclined to think—” said I.

“I should do so,” Sherlock Holmes remarked impatiently.

I believe that I am one of the most long-suffering of mortals; but I’ll admit that I was annoyed at the sardonic interruption. “Really, Holmes,” said I severely, “you are a little trying at times.”

He was too much absorbed with his own thoughts to give any immediate answer to my remonstrance. He leaned upon his hand, with his untasted breakfast before him, and he stared at the slip of paper which he had just drawn from its envelope. Then he took the envelope itself, held it up to the light, and very carefully studied both the exterior and the flap.

“It is Porlock’s writing,” said he thoughtfully. “I can hardly doubt that it is Porlock’s writing, though I have seen it only twice before. The Greek e with the peculiar top flourish is distinctive. But if it is Porlock, then it must be something of the very first importance.”

He was speaking to himself rather than to me; but my vexation disappeared in the interest which the words awakened.

“Who then is Porlock?” I asked.
\end{document}

Koska tekstissä esiintyy vanhanaikaisen ASCII-merkistön ulkopuolisia erikoismerkkejä kuten , ja , joudumme olemaan huolellisia sen suhteen, että tiedosto tallennetaan oikealla merkistökoodauksella. Nykyään oikea merkistökoodaus myös LaTeX-dokumenteissa on UTF-8; varmistathan siis, että tallennat tiedoston UTF-8-muodossa (merkistökoodauksista on paljon lisätietoa Tietokone työvälineenä -kurssin Data-moduulissa).

Jos kaikki menee hyvin, PDF:ksi käännettynä lopputuloksen pitäisi näyttää tältä:

../_images/latex-0.png

Tarina jatkuu

Nyt on sinun vuoro kokeilla! Kirjoita LaTeX-dokumentti, jossa on sisältönä tarinan jatko:

“Porlock, Watson, is a nom-de-plume, a mere identification mark; but behind it lies a shifty and evasive personality. In a former letter he frankly informed me that the name was not his own, and defied me ever to trace him among the teeming millions of this great city. Porlock is important, not for himself, but for the great man with whom he is in touch. Picture to yourself the pilot fish with the shark, the jackal with the lion—anything that is insignificant in companionship with what is formidable: not only formidable, Watson, but sinister—in the highest degree sinister. That is where he comes within my purview. You have heard me speak of Professor Moriarty?”

“The famous scientific criminal, as famous among crooks as—”

“My blushes, Watson!” Holmes murmured in a deprecating voice.

“I was about to say, as he is unknown to the public.”

“A touch! A distinct touch!” cried Holmes. “You are developing a certain unexpected vein of pawky humour, Watson, against which I must learn to guard myself. But in calling Moriarty a criminal you are uttering libel in the eyes of the law—and there lie the glory and the wonder of it! The greatest schemer of all time, the organizer of every deviltry, the controlling brain of the underworld, a brain which might have made or marred the destiny of nations—that’s the man! But so aloof is he from general suspicion, so immune from criticism, so admirable in his management and self-effacement, that for those very words that you have uttered he could hale you to a court and emerge with your year’s pension as a solatium for his wounded character. Is he not the celebrated author of The Dynamics of an Asteroid, a book which ascends to such rarefied heights of pure mathematics that it is said that there was no man in the scientific press capable of criticizing it? Is this a man to traduce? Foul-mouthed doctor and slandered professor—such would be your respective rôles! That’s genius, Watson. But if I am spared by lesser men, our day will surely come.”

PDF:ksi käännettynä lopputuloksen pitäisi näyttää tarkalleen tältä (huomaa, että LaTeX on tässä tavuttanut pitkän sanan "companionship", jotta tekstin saa aseteltua kauniisti tasapalstaan — tämä tapahtuu automaattisesti, eikä meidän tarvitse tässä tapauksessa LaTeXia mitenkään ohjeistaa):

../_images/latex-1.png

A+ esittää tässä kohdassa tehtävän palautuslomakkeen.

Erikoismerkeistä

LaTeXissa voi kaikki erikoismerkit kirjoittaa myös erilaisilla yhdistelmillä ASCII-merkkejä. Englannin kielen avautuvan lainausmerkin voi LaTeXissa latoa muodossa `` (kaksi perättäistä `-merkkiä) ja sulkevan lainausmerkin voi puolestaan latoa muodossa '' (kaksi perättäistä '-merkkiä). Pitkän ajatusviivan voi latoa muodossa --- (kolme tavuviivaa) ja lyhyen ajatusviivan puolestaan muodossa -- (kaksi tavuviivaa). Erilaisten aksenttien kirjoittamiseen on omat komentonsa; esimerkiksi sanassa "rôles" esiintyvä ô on mahdollista kirjoittaa myös muodossa \^o ja meille tutut ä ja ö voi LaTeXissa halutessaan kirjoittaa myös muodossa \"a ja \"o. Nykyään näitä harvoin enää tarvitaan, kun esimerkiksi ä ja ö on helpointa kirjoittaa suoraan lähdekoodiin muodossa ä ja ö. Mutta palataan näihin ääkkösiin kohtapuoleen…

Otsikko

Opetellaan tässä välissä muutama LaTeXin perustoiminto. Voit asettaa dokumentille otsikon komennolla \title, tekijän nimen komennolla \author ja päivämäärän komennolla \date. Nämä komennot annetaan ennen \begin{document}-käskyä. Tämän jälkeen voit käyttää \maketitle-komentoa otsikon tuottamiseen, tähän tapaan:

\documentclass{article}
\title{The Valley of Fear}
\author{Arthur Conan Doyle}
\date{1915}
\begin{document}
\maketitle

“I am inclined to think—” said I.

“I should do so,” Sherlock Holmes remarked impatiently.

I believe that I am one of the most long-suffering of mortals; but I’ll admit that I was annoyed at the sardonic interruption. “Really, Holmes,” said I severely, “you are a little trying at times.”

He was too much absorbed with his own thoughts to give any immediate answer to my remonstrance. He leaned upon his hand, with his untasted breakfast before him, and he stared at the slip of paper which he had just drawn from its envelope. Then he took the envelope itself, held it up to the light, and very carefully studied both the exterior and the flap.

“It is Porlock’s writing,” said he thoughtfully. “I can hardly doubt that it is Porlock’s writing, though I have seen it only twice before. The Greek e with the peculiar top flourish is distinctive. But if it is Porlock, then it must be something of the very first importance.”

He was speaking to himself rather than to me; but my vexation disappeared in the interest which the words awakened.

“Who then is Porlock?” I asked.
\end{document}

Lopputulos näyttää nyt tältä:

../_images/latex-2.png

Tyyliasetukset

Paperin koko voi olla LaTeX-ympäristön asetuksista riippuen oletuksena "letter", mutta tämän voi vaihtaa A4:ään antamalla \documentclass-komennolle lisäparametrin a4paper. Myös fonttikokoa voi hiukan säätää samaan tapaan; oletuksena tekstin fonttikoko on 10 pistettä, mutta valittavissa on myös 11 pisteen (11pt) ja 12 pisteen fontti (12pt). Ladotaan teksti nyt A4-paperille ja käytetään 12 pisteen fonttia:

\documentclass[a4paper,12pt]{article}
\title{The Valley of Fear}
\author{Arthur Conan Doyle}
\date{1915}
\begin{document}
\maketitle

“I am inclined to think—” said I.

“I should do so,” Sherlock Holmes remarked impatiently.

I believe that I am one of the most long-suffering of mortals; but I’ll admit that I was annoyed at the sardonic interruption. “Really, Holmes,” said I severely, “you are a little trying at times.”

He was too much absorbed with his own thoughts to give any immediate answer to my remonstrance. He leaned upon his hand, with his untasted breakfast before him, and he stared at the slip of paper which he had just drawn from its envelope. Then he took the envelope itself, held it up to the light, and very carefully studied both the exterior and the flap.

“It is Porlock’s writing,” said he thoughtfully. “I can hardly doubt that it is Porlock’s writing, though I have seen it only twice before. The Greek e with the peculiar top flourish is distinctive. But if it is Porlock, then it must be something of the very first importance.”

He was speaking to himself rather than to me; but my vexation disappeared in the interest which the words awakened.

“Who then is Porlock?” I asked.
\end{document}

Lopputulos näyttää nyt tältä:

../_images/latex-3.png

Viilailua

Lopuksi voimme vielä viilailla tekstin ulkoasua hyödyntämällä microtype-pakettia, tähän tapaan:

\documentclass[a4paper,12pt]{article}
\usepackage{microtype}
\title{The Valley of Fear}
\author{Arthur Conan Doyle}
\date{1915}
\begin{document}
\maketitle

“I am inclined to think—” said I.

“I should do so,” Sherlock Holmes remarked impatiently.

I believe that I am one of the most long-suffering of mortals; but I’ll admit that I was annoyed at the sardonic interruption. “Really, Holmes,” said I severely, “you are a little trying at times.”

He was too much absorbed with his own thoughts to give any immediate answer to my remonstrance. He leaned upon his hand, with his untasted breakfast before him, and he stared at the slip of paper which he had just drawn from its envelope. Then he took the envelope itself, held it up to the light, and very carefully studied both the exterior and the flap.

“It is Porlock’s writing,” said he thoughtfully. “I can hardly doubt that it is Porlock’s writing, though I have seen it only twice before. The Greek e with the peculiar top flourish is distinctive. But if it is Porlock, then it must be something of the very first importance.”

He was speaking to himself rather than to me; but my vexation disappeared in the interest which the words awakened.

“Who then is Porlock?” I asked.
\end{document}

Ero aiempaan ei ole silmiinpistävä, mutta tarkasti katsomalla näkee eroja etenkin siinä, miten tekstiä on venytelty koko palstan levyiseksi:

../_images/latex-4.png

Harjoitus

Nyt on sinun vuoro kokeilla samaa. Lisää omaan tiedostoosi otsikko, kirjoittaja ja vuosiluku, aseta paperikooksi A4 ja fonttikooksi 12 pistettä ja lataa myös microtype-paketti. Lopputuloksen pitäisi näyttää tältä:

../_images/latex-5.png

A+ esittää tässä kohdassa tehtävän palautuslomakkeen.

Tutki oman tiedostosi kohdalla, miten microtype-paketin lataaminen vaikutti tekstin asetteluun. Käännä dokumentti sekä ilman microtype-pakettia että sen kanssa. Avaa molemmat versiot PDF-tiedostoina ja vertaile niitä huolella toisiinsa. Mitä näet?

Paketin microtype kanssa käännettynä tekstin ensimmäinen kappale vie 9 riviä ja viimeinen kappale vie 16 riviä. Kuinka monta riviä tekstin ensimmäinen kappale vie ilman microtype-pakettia?

Entä kuinka monta riviä tekstin viimeinen kappale vie ilman microtype-pakettia?

Dokumentaatio

Voit lukea microtype-paketista lisää paketin käyttöohjeesta. Kaikki LaTeX-paketit ja niiden käyttöohjeet löytyvät CTAN-palvelusta. Omalle koneellesi asennetuista paketeista saat apua myös texdoc-komennolla; kokeile:

texdoc microtype

Tämän komennon ajamisen jälkeen microtype-paketin käyttöohjeen pitäisi avautua PDF-lukijaan. Ainakin macOS:ssa ja Linuxissa tämän pitäisi toimia suoraan.

Palautusta lähetetään...