출처: https://opensource.com/article/18/4/how-create-latex-documents-emacs
Opensource.com
In his excellent article, An introduction to creating documents in LaTeX, author Aaron Cocker introduces the LaTeX typesetting system and explains how to create a LaTeX document using TeXstudio. He also lists a few LaTeX editors that many users find helpful in creating LaTeX documents.
This comment on the article by Greg Pittman caught my attention: "LaTeX seems like an awful lot of typing when you first start...". This is true. LaTeX involves a lot of typing and debugging, if you missed a special character like an exclamation mark, which can discourage many users, especially beginners. In this article, I will introduce you to GNU Emacs and describe how to use it to create LaTeX documents.
Creating your first document
Launch Emacs by typing:
emacs -q --no-splash helloworld.org
The -q flag ensures that no Emacs initializations will load. The --no-splash-screen flag prevents splash screens to ensure that only one window is open, with the file helloworld.org.
![](https://blog.kakaocdn.net/dn/Fdzf1/btsL5iMTpVU/DINnZqsxMoUX9MOx56Pusk/img.png)
GNU Emacs with helloworld.org file opened in a buffer window.
Let's add some LaTeX headers the Emacs way: Go to Org in the menu bar and select Export/Publish.
![](https://blog.kakaocdn.net/dn/zrZ2q/btsL2zwnvDo/0cyWED7g90A8hXyoAKkChk/img.png)
How to insert a default template.
In the next window, Emacs offers options to either export or insert a template. Insert the template by entering # ([#] Insert template). This will move a cursor to a mini-buffer, where the prompt reads Options category:. At this time you may not know the category names; press Tab to see possible completions. Type "default" and press Enter. The following content will be inserted:
#+TITLE: helloworld
#+DATE: <2018-03-12 Mon>
#+AUTHOR:
#+EMAIL: makerpm@nubia
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
#+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t
#+OPTIONS: e:t email:nil f:t inline:t num:t p:nil pri:nil stat:t
#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:t todo:t |:t
#+CREATOR: Emacs 25.3.1 (Org mode 8.2.10)
#+DESCRIPTION:
#+EXCLUDE_TAGS: noexport
#+KEYWORDS:
#+LANGUAGE: en
#+SELECT_TAGS: export
Change the title, date, author, and email as you wish. Mine looks like this:
#+TITLE: Hello World! My first LaTeX document
#+DATE: \today
#+AUTHOR: Sachin Patil
#+EMAIL: psachin@redhat.com
We don't want to create a Table of Contents yet, so change the value of toc from t to nil inline, as shown below:
#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:nil todo:t |:t
Let's add a section and paragraphs. A section starts with an asterisk (*). We'll copy the content of some paragraphs from Aaron's post (from the Lipsum Lorem Ipsum generator):
* Introduction
\paragraph{}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras lorem
nisi, tincidunt tempus sem nec, elementum feugiat ipsum. Nulla in
diam libero. Nunc tristique ex a nibh egestas sollicitudin.
\paragraph{}
Mauris efficitur vitae ex id egestas. Vestibulum ligula felis,
pulvinar a posuere id, luctus vitae leo. Sed ac imperdiet orci, non
elementum leo. Nullam molestie congue placerat. Phasellus tempor et
libero maximus commodo.
![](https://blog.kakaocdn.net/dn/oDMPU/btsL4Z07m88/Ofe5lj3CmkAdpZxEzmrMlk/img.png)
Helloworld.org file
With the content in place, we'll export the content as a PDF. Select Export/Publish from the Org menu again, but this time, type l (export to LaTeX), followed by o (as PDF file and open). This not only opens PDF file for you to view, but also saves the file as helloworld.pdf in the same path as helloworld.org.
![](https://blog.kakaocdn.net/dn/8s69l/btsL4ZfJAdB/runKVfcADLetLG03SSwCG1/img.png)
Exporting helloworld.org to helloworld.pdf
![](https://blog.kakaocdn.net/dn/JJT8K/btsL3kr6JgV/rxYVadtmmwKjyO8H0KNDok/img.png)
The helloworld.pdf file opened at the bottom
You can also export org to PDF by pressing Alt + x, then typing "org-latex-export-to-pdf". Use Tab to auto-complete.
Emacs also creates the helloworld.tex file to give you control over the content.
![](https://blog.kakaocdn.net/dn/HM1jj/btsL39crMc2/AGOYHjzrGVBlARjNQym8gK/img.png)
Emacs with LaTeX, org, and PDF files open in three different windows
You can compile the .tex file to .pdf using the command:
pdflatex helloworld.tex
You can also export the .org file to HTML or as a simple text file. What I like about .org files is they can be pushed to GitHub, where they are rendered just like any other markdown formats.
Creating a LaTeX Beamer presentation
Let's go a step further and create a LaTeX Beamer presentation using the same file with some modifications as shown below:
#+TITLE: LaTeX Beamer presentation
#+DATE: \today
#+AUTHOR: Sachin Patil
#+EMAIL: psachin@redhat.com
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
#+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t
#+OPTIONS: e:t email:nil f:t inline:t num:t p:nil pri:nil stat:t
#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:nil todo:t |:t
#+CREATOR: Emacs 25.3.1 (Org mode 8.2.10)
#+DESCRIPTION:
#+EXCLUDE_TAGS: noexport
#+KEYWORDS:
#+LANGUAGE: en
#+SELECT_TAGS: export
#+LATEX_CLASS: beamer
#+BEAMER_THEME: Frankfurt
#+BEAMER_INNER_THEME: rounded
* Introduction
*** Programming
- Python
- Ruby
*** Paragraph one
Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Cras lorem nisi, tincidunt tempus sem nec, elementum feugiat
ipsum. Nulla in diam libero. Nunc tristique ex a nibh egestas
sollicitudin.
*** Paragraph two
Mauris efficitur vitae ex id egestas. Vestibulum
ligula felis, pulvinar a posuere id, luctus vitae leo. Sed ac
imperdiet orci, non elementum leo. Nullam molestie congue
placerat. Phasellus tempor et libero maximus commodo.
* Thanks
*** Links
- Link one
- Link two
We have added three more lines to the header:
#+LATEX_CLASS: beamer
#+BEAMER_THEME: Frankfurt
#+BEAMER_INNER_THEME: rounded
To export to PDF, press Alt + x and type "org-beamer-export-to-pdf".
![](https://blog.kakaocdn.net/dn/eu9jjn/btsL25u8wXj/3GErq0kPGROluKF1KmfXk1/img.png)
Latex Beamer presentation created using Emacs and Org mode
I hope you enjoyed creating this LaTeX and Beamer document using Emacs (note that it's faster to use keyboard shortcuts than a mouse). Emacs Org-mode offers much more than I can cover in this post; you can learn more at orgmode.org.
'프로그램 개발(분석, 설계, 코딩, 배포) > 100. 기타' 카테고리의 다른 글
LaTeX로 논문 쓰기 - 입문편 (0) | 2025.02.02 |
---|---|
응용프로그램 사용법 (0) | 2025.02.01 |
Windows, Chocolatey, TeXLive 설치가이드 (0) | 2025.02.01 |
리눅스 vim 설정 (0) | 2025.01.31 |
중국어 공부 - 중국 동영상 사이트(유쿠, 투도우 등)로 중국 영화 보는 방법, 지역 제한 풀기 (0) | 2025.01.30 |