Pandoc 및 외국 문자
일부 Markdown을 PDF 파일로 변환하기 위해 Pandoc을 사용하려고했습니다. 다음은 Pandoc에서 변환하지 않는 샘플입니다.
# Header!
## Sub Header
themselves derived respectively from the Greek ἀναρχία i.e. 'anarchy'
그것은 내가 위키피디아 데이터베이스 덤프의 상단에서 얻은 것입니다. Pandoc은 그것을 전혀 좋아하지 않습니다. 이것은 나에게 제공하는 오류 메시지입니다.
pandoc: Error producing PDF from TeX source.
! Package inputenc Error: Unicode char \u8:ἀ not set up for use with LaTeX.
See the inputenc package documentation for explanation.
Type H <return> for immediate help.
...
l.53 ...es derived respectively from the Greek ἀ
이 문제를 해결할 수있는 명령 스위치가 있습니까? 나는 이런 일을하기 위해 조언을 따르려고했지만 실패했다.
iconv -t utf-8 test.md | pandoc -o test.pdf
업데이트 아래 John의 조언을 따르기 전에 이를 참조하십시오 .
업데이트 2 이것은 궁극적으로 작동하게 만든 명령입니다. 바라건대 이것은 누군가를 도울 것입니다.
pandoc test2.md -o test2.pdf --latex-engine=xelatex --template=my.latex --variable mainfont="DejaVu Serif" --variable sansfont=Arial
그리고 이것은 다음의 내용입니다 my.latex
.
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$]{$documentclass$}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
% use microtype if available
\IfFileExists{microtype.sty}{\usepackage{microtype}}{}
% use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[utf]{inputenc}
\usepackage{ucs}
$if(euro)$
\usepackage{eurosym}
$endif$
\else % if luatex or xelatex
\usepackage{fontspec}
\ifxetex
\usepackage{xltxtra,xunicode}
\fi
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
\setromanfont{TeX Gyre Pagella}
\newcommand{\euro}{€}
$if(mainfont)$
\setmainfont{$mainfont$}
$endif$
$if(sansfont)$
\setsansfont{$sansfont$}
$endif$
$if(monofont)$
\setmonofont{$monofont$}
$endif$
$if(mathfont)$
\setmathfont{$mathfont$}
$endif$
\fi
$if(geometry)$
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
$endif$
$if(natbib)$
\usepackage{natbib}
\bibliographystyle{plainnat}
$endif$
$if(biblatex)$
\usepackage{biblatex}
$if(biblio-files)$
\bibliography{$biblio-files$}
$endif$
$endif$
$if(listings)$
\usepackage{listings}
$endif$
$if(lhs)$
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
$endif$
$if(highlighting-macros)$
$highlighting-macros$
$endif$
$if(verbatim-in-note)$
\usepackage{fancyvrb}
$endif$
$if(tables)$
\usepackage{longtable}
$endif$
$if(graphics)$
\usepackage{graphicx}
% We will generate all images so they have a width \maxwidth. This means
% that they will get their normal width if they fit onto the page, but
% are scaled down if they would overflow the margins.
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
\else\Gin@nat@width\fi}
\makeatother
\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}
$endif$
\ifxetex
\usepackage[setpagesize=false, % page size defined by xetex
unicode=false, % unicode breaks when used with xetex
xetex]{hyperref}
\else
\usepackage[unicode=true]{hyperref}
\fi
\hypersetup{breaklinks=true,
bookmarks=true,
pdfauthor={$author-meta$},
pdftitle={$title-meta$},
colorlinks=true,
urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,
linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$,
pdfborder={0 0 0}}
\urlstyle{same} % don't use monospace font for urls
$if(links-as-notes)$
% Make links footnotes instead of hotlinks:
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$if(strikeout)$
\usepackage[normalem]{ulem}
% avoid problems with \sout in headers with hyperref:
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
$endif$
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em} % prevent overfull lines
$if(numbersections)$
$else$
\setcounter{secnumdepth}{0}
$endif$
$if(verbatim-in-note)$
\VerbatimFootnotes % allows verbatim text in footnotes
$endif$
$if(lang)$
\ifxetex
\usepackage{polyglossia}
\setmainlanguage{$mainlang$}
\else
\usepackage[$lang$]{babel}
\fi
$endif$
$for(header-includes)$
$header-includes$
$endfor$
$if(title)$
\title{$title$}
$endif$
\author{$for(author)$$author$$sep$ \and $endfor$}
\date{$date$}
\begin{document}
$if(title)$
\maketitle
$endif$
$for(include-before)$
$include-before$
$endfor$
$if(toc)$
{
\hypersetup{linkcolor=black}
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
}
$endif$
$body$
$if(natbib)$
$if(biblio-files)$
$if(biblio-title)$
$if(book-class)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\bibliography{$biblio-files$}
$endif$
$endif$
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
$endif$
$for(include-after)$
$include-after$
$endfor$
\end{document}
--pdf-engine=xelatex
옵션을 사용하십시오 .
기본적으로 Pandoc은 pdflatex
마크 다운 파일을 pdf 파일로 변환 할 때 엔진을 사용 합니다. pdflatex
유니 코드 문자를 xelatex
. xelatex
대신 시도해야 합니다. 그러나 , 단순히 사용하여 xelatex
명령하는 것만으로는 충분하지 않습니다. 종종 그렇듯이 조판하려는 유니 코드 문자의 글리프가 포함 된 적절한 글꼴을 선택해야합니다.
저는 중국 사용자이므로 중국어를 예로 들어 보겠습니다. 당신이있는 경우 test.md
다음과 같은 내용을 포함하는 :
你好 汉字
다음 명령을 사용하여이 마크 다운 파일을 컴파일 할 수 있습니다.
pandoc --pdf-engine=xelatex -V CJKmainfont="KaiTi" test.md -o test.pdf
위의 명령에서는 --pdf-engine=xelatex
LaTeX 엔진을 선택하는 데 사용됩니다 (Pandoc의 새 버전의 경우 --latex-engine
옵션은 더 이상 사용되지 않음 ). -V CJKmainfont="KaiTi"
중국어를 지원하는 적절한 글꼴을 선택하는 데 사용됩니다. 다른 언어의 경우 플래그를 사용할 수 있습니다 -C mainfont="<FONT_NAME>"
.
귀하의 언어를 지원하는 글꼴을 찾는 방법
귀하의 언어를 지원하는 글꼴을 찾으려면 귀하의 언어 코드 를 알아야합니다 . 그런 다음 Linux 시스템 또는 TeX Live가 설치된 Windows 시스템에있는 경우. 다음 명령을 사용하여 언어에 맞는 유효한 글꼴을 찾을 수 있습니다.
fc-list :lang=zh #find the font which support Chinese (language code is `zh`)
예를 들어 font Source Han Serif CN
를 사용하기로 선택한 경우 다음 명령을 사용하여 마크 다운 파일을 컴파일하십시오.
pandoc --pdf-engine=xelatex -V CJKmainfont="Source Han Serif CN" test.md -o test.pdf
5 년 후에이 게시물로 돌아 왔지만 문제는 여전히 존재합니다. 명령
pandoc -s test.md -t latex -o test.pdf
test.md
라틴어가 아닌 문자, 그리스어, 키릴 문자, CJK, 히브리어 및 아랍어가 포함 된 텍스트가 포함 된 경우 실패합니다 .
LaTeX는 유니 코드 이전에 설계되었으며 다른 문자 집합에 대한 지원은 일부 영역에서 강력하지만 포괄적 인 것은 아니므로 XeLaTeX 사용에 대한 조언은 유효하지만 자동 선택이 없기 때문에 주 글꼴을 신중하게 선택해야합니다.
다음은 가능한 문제와 몇 가지 솔루션에 대한 작은 분류입니다. 모두 Pandoc 1.19로 테스트되었습니다 .
키릴 문자
LaTeX의 키릴 문자 지원은 T2A 글꼴 인코딩을 통해 제공됩니다.
작은 샘플을 고려하십시오.
# Header
## Subheader
Tetris (Russian: Тетрис) quoting Wikipedia is a tile-matching puzzle
video game
pandoc로이 예제를 실행하면 다음과 같이 실패합니다.
! Package inputenc Error: Unicode char Т (U+422)
(inputenc) not set up for use with LaTeX.
See the inputenc package documentation for explanation.
fontenc
옵션은 default.latex
템플릿에 미리 정의 된 변수이므로 수정 사항을 사용할 수 있습니다 .
이 예제 실행
pandoc -t latex -o tetris.pdf -V fontenc=T2A cyrillic.md
올바른 렌더링을 생성합니다.
그러나 이것은 하이픈과 같은 다른 언어 기능을 올바르게 처리하지 못합니다. 더 좋은 방법은 Babel을 사용하고 올바른 글꼴 인코딩을 선택하도록하는 것입니다.
pandoc -t latex -o tetris.pdf -V lang -V babel-lang=russian cyrillic.md
또는 Markdown 내에서 Babel 명령으로 언어를 전환하려면
# Header
## Subheader
Tetris (Russian: \foreignlanguage{russian}{Тетрис}) quoting Wikipedia
is a tile-matching puzzle video game
그리고
pandoc -t latex -o tetris.pdf -V lang -V babel-lang=english \
-V babel-otherlangs=russian cyrillic2.md
그리스 어
원본 게시물의 예에는 기본 및 확장 그리스어 유니 코드 코드 페이지의 문자가 모두 포함되어 있습니다.
어쨌든 널리 사용되는 LGR 그리스어 글꼴 인코딩은 LaTeX 3 프로젝트에서 다루지 않으며 로컬 인코딩 으로 분류됩니다. 즉, LaTeX 인코딩 가이드 에 따라 사이트마다, 시스템마다 다를 수 있습니다 .
텍 라이브에 다음 패키지를 설치해야합니다 : texlive-greek-inputenc
, texlive-greek-fontenc
및 texlive-cbfonts
. Babel 3.9 이상이 필요합니다 . 그러나 결과
pandoc -t latex -o anarchy.pdf -V fontenc=LGR greek.md
예기치 않게 나타날 수 있습니다.
이 문제를 해결하려면 LaTeX Babel 패키지를 올바르게 설정해야합니다. 그리고 원본 텍스트의 언어간에 전환하는 명령을 삽입합니다.
# Header!
## Sub Header
themselves derived respectively from the Greek \textgreek{ἀναρχία}
i.e. 'anarchy'
다음 명령으로 컴파일
pandoc -s greek2.md -t latex -V fontenc=T2A -V lang -V babel-lang=english \
-V babel-otherlangs=greek -o greek.pdf
예상대로 정확히 출력을 생성합니다.
XeLaTeX
XeLaTeX를 사용한다면이 모든 것이 필요하지 않을 것입니다.
원래 예제를
pandoc -s greek.md --latex-engine=xelatex -t latex -o greek.pdf
생산할 것이다
글꼴에는 그리스 문자 위치에 아무것도 포함되어 있지 않기 때문에 출력에 공백이 대신 포함됩니다.
인기있는 글꼴 중 하나를 새 글꼴로 선택하면 mainfont
도움이 될 것입니다.
pandoc -s greek.md --latex-engine=xelatex \
-V mainfont="Liberation Serif" -t latex -o greek.pdf
However characters from the extended Greek codepage such as the small letter alpha with psili accent are not rendered.
The Font Setup for Greek with XeTeX/LuaTeX Guide suggests to use DejaVu, Libertine or Free font families.
Indeed with DejaVu Serif
, Linux Libertine O
as well as Tempora
and perhaps some other fonts, the result would be as expected. See below the rendering with XeLaTeX and Linux Libertine fonts.
pandoc -s greek.md --latex-engine=xelatex -V mainfont="Linux Libertine O" \
-t latex -o greek.pdf
If you are using LaTeX intermediate output, then you can use inline \mbox{t\'ext}
to get accented characters. Without the \mbox{}
, the backslash often isn't interpreted correctly by the Pandoc parser.
--latex-engine=xelatex
앞서 말했듯이을 사용할 수 있지만 내가 찾은 최선의 방법은 lang
변수를 사용하여 다음과 같이 헤더에 문서 언어를 지정하는 것 lang: ru-RU
입니다. 내 데비안 워크 스테이션의 작업 예 :
---
title: Lady Macbeth de Mzensk (Chostakovitch, livret d'Alexandre Preis, 1934)
lang: ru-RU
---
# Acte I / Tableau 1
*[Народ ненадежный]*
Ха, ха, ха, ха, ха, ха, ха. *[...]* Чуыствуем
На кого ты нас покидаешь?
Без хозяина будет скучно,
скучно, тоскливо, безрадостно.
Не работа. Без тебя невеселье. Воз вращайся
Как можно скорей, скорей !
그런 다음 시작할 수 있습니다.
$ pandoc -o your-file-output.pdf your-source-file.md
출력에 표시 할 수학적 기호를 얻으려는 비슷한 문제가 발생했습니다.
다른 사람들이 언급했듯이 최신 pandoc 버전 (내 경우에는 v2.2.3.2)에서 사용할 수있는 옵션은 pdf-engine=xelatex
. 이 경우 글꼴을 지정할 필요가 없습니다.
pandoc -o MyDoc.pdf --pdf-engine=xelatex MyDoc.md
latinmodern-math 글꼴이 없다는 오류가 발생했습니다. 다음을 사용하여 설치했습니다.
tlmgr install collection-fontsrecommended
키릴 문자에서 작동
pandoc myfile.md --pdf-engine=xelatex -V mainfont=Arial
참조 URL : https://stackoverflow.com/questions/18178084/pandoc-and-foreign-characters
'Development Tip' 카테고리의 다른 글
블룸 필터의 반대? (0) | 2020.12.31 |
---|---|
char *와 std :: uint8_t * 사이의 reinterpret_cast-안전합니까? (0) | 2020.12.31 |
TypeScript 코딩 스타일 가이드? (0) | 2020.12.31 |
prettify.js를 확장하여 Mathematica를 지원할 수 있습니까? (0) | 2020.12.31 |
-webkit-overflow-scrolling : 터치; (0) | 2020.12.31 |