Outils pour utilisateurs

Outils du site


issue218:latex

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
issue218:latex [2025/06/30 07:22] d52frissue218:latex [2025/06/30 15:49] (Version actuelle) d52fr
Ligne 2: Ligne 2:
  
 First I need to have a text file for the selected book. It is available in three different epub formats on the Gutenberg site as well as two Kindle formats, and a html and a plain text file which is the one I want. The text file needs to be edited somewhat. The Table of Contents needs to be removed because Latex will build a new one. I removed the Gutenberg Licence since I plan to print and bind one copy as a gift. I saved the txt file as an odt file using LibreOffice. Then I used the Writer2Latex filter extension to convert the file to the tex format. ** First I need to have a text file for the selected book. It is available in three different epub formats on the Gutenberg site as well as two Kindle formats, and a html and a plain text file which is the one I want. The text file needs to be edited somewhat. The Table of Contents needs to be removed because Latex will build a new one. I removed the Gutenberg Licence since I plan to print and bind one copy as a gift. I saved the txt file as an odt file using LibreOffice. Then I used the Writer2Latex filter extension to convert the file to the tex format. **
 +
 +Cette fois, je vais travailler avec un vrai document, et non avec l'un des milliers de logiciels disponibles sur ctan.org. Je vais convertir le fichier texte d'un livre existant en fichier PDF LaTeX. J'ai eu l'idée de ce projet après avoir vu un relieur professionnel imprimer et relier un livre à partir d'un PDF sur YouTube. Le fichier de départ que j'utiliserai est le fichier texte d'un livre pour enfants intitulé Whitefoot the Wood Mouse de Thornton W. Burgess. Burgess était l'un de mes auteurs préférés à l'école primaire. Il a écrit plus de 170 livres et plus de 15 000 histoires. Certains de ces livres sont disponibles sur gutenberg.org.
 +
 +Je dois d'abord disposer d'un fichier texte pour le livre sélectionné. Il est disponible en trois formats epub différents sur le site de Gutenberg, ainsi qu'en deux formats Kindle, un fichier HTML et un fichier texte brut, celui que je souhaite. Le fichier texte doit être légèrement modifié. La table des matières doit être supprimée, car LaTeX en créera une nouvelle. J'ai supprimé la licence Gutenberg car je prévois d'imprimer et de relier un exemplaire pour l'offrir. J'ai enregistré le fichier txt au format .odt avec LibreOffice. J'ai ensuite utilisé l'extension de filtre Writer2LaTeX pour convertir le fichier au format .tex.
 +
  
 **Once the file has been converted, I opened the tex file in my preferred editor, TexStudio, to do the cleanup. Of course I could do some of the cleanup in the odt file before converting it to a tex file. I could also edit the tex file LibreOffice generated in a text editor but I like the advantage of the color coding in TexStudio. I find it easier and faster to work with the tex file instead of the odt file. **Once the file has been converted, I opened the tex file in my preferred editor, TexStudio, to do the cleanup. Of course I could do some of the cleanup in the odt file before converting it to a tex file. I could also edit the tex file LibreOffice generated in a text editor but I like the advantage of the color coding in TexStudio. I find it easier and faster to work with the tex file instead of the odt file.
  
 The first thing I did was generate the pdf file using TexStudio before I started editing. I wanted to be sure it was error free before I started deleting unnecessary code. Good thing I compiled first. LibreOffice inserted two Latex commands to make the Table of Contents clickable but there was an error somewhere in the hypersetup command. Since I intend to print the generated pdf file on paper, any hypertext links are irrelevant. So I commented out both the hypersetup and the usepackage{hyperref} commands from the generated file. Since that cleared the error I then deleted those two commands.** The first thing I did was generate the pdf file using TexStudio before I started editing. I wanted to be sure it was error free before I started deleting unnecessary code. Good thing I compiled first. LibreOffice inserted two Latex commands to make the Table of Contents clickable but there was an error somewhere in the hypersetup command. Since I intend to print the generated pdf file on paper, any hypertext links are irrelevant. So I commented out both the hypersetup and the usepackage{hyperref} commands from the generated file. Since that cleared the error I then deleted those two commands.**
 +
 +Une fois le fichier converti, j'ai ouvert le fichier .tex dans mon éditeur préféré, TexStudio, pour le nettoyer. Bien sûr, je pourrais effectuer une partie du nettoyage dans le fichier .odt avant de le convertir en fichier .tex. Je pourrais également modifier le fichier .tex généré par LibreOffice dans un éditeur de texte, mais j'apprécie l'avantage du codage couleur de TexStudio. Je trouve plus simple et plus rapide de travailler avec le fichier .tex qu'avec le fichier .odt.
 +
 +J'ai d'abord généré le fichier PDF avec TexStudio avant de commencer à le modifier. Je voulais m'assurer qu'il ne comportait aucune erreur avant de supprimer le code inutile. Heureusement, j'ai compilé au préalable. LibreOffice a inséré deux commandes LaTeX pour rendre la table des matières cliquable, mais une erreur s'est produite dans la commande hypersetup. Comme je prévois d'imprimer le fichier PDF généré sur papier, les liens hypertextes sont inutiles. J'ai donc commenté les commandes hypersetup et usepackage{hyperref} du fichier généré. Comme l'erreur a été résolue ainsi, j’ai ensuite supprimé ces deux commandes.
 +
  
 **Remember each time you make a change to the Latex commands, regenerate the PDF. This will check for errors in the code and it will also save the current code. Doing this step after every change is a little time consuming. However, I learned long ago when making changes to code (or just about anything) change one thing then make sure it works as you want, then change the next one thing and check again. **Remember each time you make a change to the Latex commands, regenerate the PDF. This will check for errors in the code and it will also save the current code. Doing this step after every change is a little time consuming. However, I learned long ago when making changes to code (or just about anything) change one thing then make sure it works as you want, then change the next one thing and check again.
  
 There were a number of “length” commands which were generated by LibreOffice in order to be sure the geometry of the Latex-generated PDF document would match the page style used in LibreOffice. I will set page size, printed area size, and other page geometry options later in the Latex process, so I removed those length commands. There was a short section of footnote rules and another section of page styles. Both are not needed so I removed them. Then I generated the PDF again to check for any errors. This time there were no errors. Next I made necessary corrections to the title and author in the preamble. That made the title and author in the body redundant so they were removed.** There were a number of “length” commands which were generated by LibreOffice in order to be sure the geometry of the Latex-generated PDF document would match the page style used in LibreOffice. I will set page size, printed area size, and other page geometry options later in the Latex process, so I removed those length commands. There was a short section of footnote rules and another section of page styles. Both are not needed so I removed them. Then I generated the PDF again to check for any errors. This time there were no errors. Next I made necessary corrections to the title and author in the preamble. That made the title and author in the body redundant so they were removed.**
 +
 +N'oubliez pas de régénérer le PDF à chaque modification des commandes LaTeX. Cela vérifiera les erreurs dans le code et enregistrera le code actuel. Répéter cette étape après chaque modification est un peu long. Cependant, j'ai appris il y a longtemps qu'en modifiant du code (ou quoi que ce soit), il faut modifier un élément, s'assurer qu'il fonctionne correctement, puis modifier l'élément suivant et vérifier à nouveau.
 +
 +LibreOffice générait plusieurs commandes « length » afin de garantir que la géométrie du document PDF généré par LaTeX corresponde au style de page utilisé dans LibreOffice. Je définirai la taille de la page, la taille de la zone d'impression et d'autres options de géométrie de page plus tard dans le processus LaTeX ; j'ai donc supprimé ces commandes length. Il y avait une courte section consacrée aux règles des notes de bas de page et une autre section consacrée aux styles de page. Ces deux sections étant inutiles, je les ai supprimées. J'ai ensuite regénéré le PDF pour vérifier les éventuelles erreurs. Cette fois, aucune erreur n'a été détectée. J'ai ensuite apporté les corrections nécessaires au titre et à l'auteur dans le préambule. Le titre et l'auteur dans le corps du texte étant devenus redondants, ils ont été supprimés.
 +
  
 **I noticed every paragraph of the text started with {\ttfamily{ and ended with a closing curly brace. While those defined the paragraph, they were unnecessary, because every paragraph was separated from the next one with at least two CR/LF (two presses of the <enter> key). Two CR/LF codes is the necessary indicator in Latex to separate paragraphs. This ttfamily command also sets the font for all the text to “tt” – a monospaced font family which is inappropriate unless you desire text that looks as if it were made with a typewriter. I eliminated \ttfamily{ ...} for the first two paragraphs to make sure this was safe. No problems I could see. So I used Search and Replace in TexStudio and deleted them all. **I noticed every paragraph of the text started with {\ttfamily{ and ended with a closing curly brace. While those defined the paragraph, they were unnecessary, because every paragraph was separated from the next one with at least two CR/LF (two presses of the <enter> key). Two CR/LF codes is the necessary indicator in Latex to separate paragraphs. This ttfamily command also sets the font for all the text to “tt” – a monospaced font family which is inappropriate unless you desire text that looks as if it were made with a typewriter. I eliminated \ttfamily{ ...} for the first two paragraphs to make sure this was safe. No problems I could see. So I used Search and Replace in TexStudio and deleted them all.
  
 As I scrolled through the tex file, I saw the \bigskip command many times. This is used by Latex to make large vertical areas of white space. I assume the Writer2Latex extension converted multiple CR/LF codes to bigskip. Since I will use other Latex instructions to control white space, I removed the bigskip commands as well. Again I generated the PDF and scrolled through it to make sure there was no inappropriate white space and no long paragraphs. (This is a children’s book, so paragraphs should be short, two or three sentences. If you are working with a different file then adjust your editing accordingly.)** As I scrolled through the tex file, I saw the \bigskip command many times. This is used by Latex to make large vertical areas of white space. I assume the Writer2Latex extension converted multiple CR/LF codes to bigskip. Since I will use other Latex instructions to control white space, I removed the bigskip commands as well. Again I generated the PDF and scrolled through it to make sure there was no inappropriate white space and no long paragraphs. (This is a children’s book, so paragraphs should be short, two or three sentences. If you are working with a different file then adjust your editing accordingly.)**
 +
 +J'ai remarqué que chaque paragraphe du texte commençait par {\ttfamily{ et se terminait par une accolade fermante. Bien que ces accolades définissent le paragraphe, elles étaient inutiles, car chaque paragraphe était séparé du suivant par au moins deux CR/LF (deux appuis sur la touche <Entrée>). Deux codes CR/LF sont l'indicateur nécessaire dans LaTeX pour séparer les paragraphes. Cette commande ttfamily définit également la police de l'ensemble du texte sur « tt », une famille de polices à espacement fixe, inappropriée sauf si vous souhaitez un texte qui semble avoir été écrit à la machine à écrire. J'ai supprimé \ttfamily{ ...} pour les deux premiers paragraphes par mesure de sécurité. Aucun problème constaté. J'ai donc utilisé la fonction Rechercher/Remplacer dans TexStudio et les ai tous supprimés.
 +
 +En parcourant le fichier tex, j'ai vu la commande \bigskip à plusieurs reprises. Elle est utilisée par LaTeX pour créer de grandes zones verticales d'espaces blancs. Je suppose que l'extension Writer2Latex a converti plusieurs codes CR/LF en bigskip. Comme j'utiliserai d'autres instructions LaTeX pour gérer les espaces blancs, j'ai également supprimé les commandes bigskip. J'ai de nouveau généré le PDF et l'ai parcouru pour vérifier qu'il ne contenait aucun espace blanc inapproprié ni de longs paragraphes. (Il s'agit d'un livre pour enfants ; les paragraphes doivent donc être courts, deux ou trois phrases. Si vous travaillez avec un autre fichier, ajustez vos modifications en conséquence.)
 +
  
 **This finished the majority of the cleanup. Then it was time to make this text file look more like a book. At this point in the editing process, the PDF was 33 full letter-size pages. The document class was article, and the default type size was 10pt. This is a book for children. It was originally printed and bound in a size suitable to be held by small hands. Like most books, each chapter should start on a separate page.  **This finished the majority of the cleanup. Then it was time to make this text file look more like a book. At this point in the editing process, the PDF was 33 full letter-size pages. The document class was article, and the default type size was 10pt. This is a book for children. It was originally printed and bound in a size suitable to be held by small hands. Like most books, each chapter should start on a separate page. 
Ligne 22: Ligne 42:
  
 Latex automatically numbers chapters. If the text you work with has chapter numbers, as Whitefoot the Wood Mouse did, you should probably delete them when you edit the chapter command.** Latex automatically numbers chapters. If the text you work with has chapter numbers, as Whitefoot the Wood Mouse did, you should probably delete them when you edit the chapter command.**
 +
 +Ceci a permis d'achever la majeure partie du nettoyage. Il était ensuite temps de donner à ce fichier texte l'aspect d'un livre. À ce stade du processus d'édition, le PDF comptait 33 pages au format letter. La classe de document était « article » et la taille de police par défaut était de 10 pt. Il s'agit d'un livre pour enfants. Il a été initialement imprimé et relié dans un format adapté aux petites mains. Comme la plupart des livres, chaque chapitre doit commencer sur une page distincte.
 +
 +J'ai changé la classe de document en « book » et la police par défaut en « Noto Serif ». Afin de tirer parti du formatage des titres intégré, j'ai stylisé chaque titre de chapitre comme un chapitre. La fonction Rechercher/Remplacer m'a été d'une grande aide. Le texte original comporte le mot « CHAPITRE » au début de chaque titre. Il est facile de remplacer le mot « CHAPITRE » par la commande \chapter pour chaque titre. Trois points sont à prendre en compte :
 +
 +• Les chapitres ne sont autorisés que dans la classe de document « book », modifiez-la donc en premier.
 +• Le texte de chaque chapitre doit être entre accolades ; chaque titre de chapitre nécessite donc une attention particulière.
 +
 +LaTeX numérote automatiquement les chapitres. Si le texte que vous utilisez comporte des numéros de chapitre, comme c'était le cas de Whitefoot the Wood Mouse, il est préférable de les supprimer lorsque vous modifiez la commande de chapitre.
 +
  
 **Note: If you do not want the automatic chapter numbering then change the \chapter command to \chapter*, i.e. add an asterisk after the word “chapter”. This also removes the chapter from the Table of Contents. **Note: If you do not want the automatic chapter numbering then change the \chapter command to \chapter*, i.e. add an asterisk after the word “chapter”. This also removes the chapter from the Table of Contents.
Ligne 28: Ligne 58:
  
 I adjusted the leading (spacing between lines), and added a paragraph indent. After I use the geometry package (next issue), I will look at a printed page to find out if I think my work is usable by primary school students. I am also considering using drop caps, large initial capital letters at the beginning of the first paragraph of each chapter. Perhaps I can find some illustrations to add to the text. These are tasks for the time.** I adjusted the leading (spacing between lines), and added a paragraph indent. After I use the geometry package (next issue), I will look at a printed page to find out if I think my work is usable by primary school students. I am also considering using drop caps, large initial capital letters at the beginning of the first paragraph of each chapter. Perhaps I can find some illustrations to add to the text. These are tasks for the time.**
 +
 +Remarque : Si vous ne souhaitez pas la numérotation automatique des chapitres, remplacez la commande \chapter par \chapter*, c'est-à-dire ajoutez un astérisque après le mot « chapter ». Cela supprime également le chapitre de la table des matières.
 +
 +De nombreux chapitres de Whitefoot the Wood Mouse commencent par des poèmes de deux lignes. Le texte de ces poèmes commence par une accolade ou une barre oblique inverse, ce qui peut poser problème lors de la compilation du fichier. Lors de la modification des commandes de chapitre, j'ai également supprimé les éléments gênants. Ces poèmes de deux lignes m'ont rappelé un paquet que j'ai examiné dans FCM n° 212, qui formate de petits extraits de texte au début des chapitres. Ce paquet, appelé epigraph, est très simple à utiliser. Cependant, ce petit livre contenait de nombreuses épigraphes. L'ajout du code pour que chaque épigraphe soit codée comme une épigraphe a pris du temps. Ces modifications ont dû être effectuées individuellement. L'utilisation de la fonction Rechercher/Remplacer aurait pu éliminer toutes les barres obliques inverses et les accolades du fichier, et pas seulement celles des épigraphes. Cela aurait demandé plus de travail que je ne le pensais.
 +
 +J'ai ajusté l'interligne (espacement entre les lignes) et ajouté un retrait de paragraphe. Après avoir utilisé le logiciel de géométrie (prochain numéro), je consulterai une page imprimée pour voir si mon travail est utilisable par des élèves de primaire. J'envisage également d'utiliser des lettrines, des lettres majuscules initiales de grande taille au début du premier paragraphe de chaque chapitre. Je pourrais peut-être trouver des illustrations à ajouter au texte. Ce sont des tâches ponctuelles.
 +
  
 **Here is the code (with a few comments) for the preamble so far followed by the code to make an epigraph. **Here is the code (with a few comments) for the preamble so far followed by the code to make an epigraph.
Ligne 39: Ligne 76:
  
 For the second part of this project, I am going to add a drop cap in the first paragraph of each chapter to add a little visual interest. I will alter the page geometry to get the file ready for imposition. Imposition is a process used to put the text on the correct printed pages in order to bind them into a book. If you do not need or want to make your file into a printed book, then imposition is not necessary. However you might want to change the page geometry to make the PDF look more like a printed book. If I can find some suitable illustrations I may include them. I hope you will join me next time.** For the second part of this project, I am going to add a drop cap in the first paragraph of each chapter to add a little visual interest. I will alter the page geometry to get the file ready for imposition. Imposition is a process used to put the text on the correct printed pages in order to bind them into a book. If you do not need or want to make your file into a printed book, then imposition is not necessary. However you might want to change the page geometry to make the PDF look more like a printed book. If I can find some suitable illustrations I may include them. I hope you will join me next time.**
 +
 +Voici le code (avec quelques commentaires) du préambule, suivi du code pour créer une épigraphe.
 +
 +Pour créer une épigraphe, j'ai utilisé :
 +
 +\epigraph{You never can tell! You never can tell! 
 +Things going wrong will often end well.}{Whitefoot}
 +
 +(On ne sait jamais ! On ne sait jamais ! Les erreurs finissent souvent bien. - Whitefoot)
 +
 +Cette chronique contient des images d'une épigraphe et du début d'un chapitre.
 +
 +Pour la deuxième partie de ce projet, je vais ajouter une lettrine au premier paragraphe de chaque chapitre pour un rendu visuel plus intéressant. Je modifierai la géométrie de la page afin de préparer le fichier pour l'imposition. L'imposition est un procédé permettant de placer le texte sur les pages imprimées appropriées afin de les relier pour former un livre. Si vous n'avez pas besoin ou ne souhaitez pas imprimer votre fichier, l'imposition n'est pas nécessaire. Cependant, vous pouvez modifier la géométrie de la page pour que le PDF ressemble davantage à un livre imprimé. Si je trouve des illustrations appropriées, je les inclurai peut-être. J'espère que vous me rejoindrez la prochaine fois.
  
issue218/latex.txt · Dernière modification : 2025/06/30 15:49 de d52fr