如何将带有日语的Markdown文档转换为Beamer?

时间:2015-05-21 21:20:58

标签: macos pdf markdown pandoc beamer

例如,我有这个Markdown文档:

## Markdown test

Japanese 日本語

我跑:

pandoc mwe.rmd -t beamer -o mwe.pdf --latex-engine=xelatex -V mainfont=MS\ Mincho

单词日本语在结果文件中消失了。如果我不使用Beamer模板,那么它可以正常工作。

我不必使用pandoc。在Mac(使用MacTex)上从Markdown到PDF(幻灯片)的任何东西对我都有用。

如果没有简单的解决方案,我会对任何导致非Beamer PDF幻灯片的内容感到满意。

1 个答案:

答案 0 :(得分:3)

I'm assuming that you do have installed a font named MS Mincho on your system, and it shows up when your start the Font Book.app? (Looks like, otherwise your "normal" PDF output wouldn't work, but you said it does...)

There are various options to check and verify, which exact font name you should use.

1. Font Book.app (GUI application)

  1. Start Font Book.app.
  2. Type mincho into the top right search box.
  3. All installed fonts with 'Mincho' in their names show up.
  4. Click on one of the font faces (NOT the main entry!) in the list.
  5. A font sample will be displayed.
  6. Click on the button with the little i-logo.
  7. The font's metadata will display.

From the font's metadata you can infer the PostScript name and the Full name of the font. Both should work with XeLaTeX. (I usually put quotes around font names with spaces: -V mainfont="YuMincho Medium"

Here is a screenshot with the relevant parts of the Font Book.app UI highlighted in red. Sorry, I do not have MS Mincho installed, I can only show it with another font:

Font Book.app, screenshot

2. fc-list (command line utility)

  1. fc-list is a command line utility that is available via the MacPorts fontconfig package.
  2. If you have it installed, use it.
  3. To get a list of font names available for XeTeX, you can simply run:

    fc-list -f "%{family}\n"
    fc-list :outline -f "%{family}\n"
    

    The second command suppresses the listing of bitmap only fonts. Such fonts are unusable for TeX. -- For some more verbosity, and a nice formatting of the info, you could also run:

    fc-list :outline -f "  family: %{family}\nfullname: %{fullname}\n    file: %{file}\n\n"
    
  4. To get a list of names containing 'Mincho', run:

    fc-list -f "%{family}\n" | grep -i mincho
    

Change your setup

Now that this smaller problem ("Which font names should I use?") is out of the way, lets deal with your main one:

  • The Pandoc Beamer template (and standard Beamer itself) does not use the \setmainfont command. Therefor putting -V mainfont=... onto the Pandoc command line does not do anything.

You can check this by querying the default internal template used by Pandoc to produce beamer output:

$ pandoc -D beamer | less

Search for a $mainfont$ variable in there and you'll find none!

You have to modify your setup a bit to get success:

  1. First, create a simple text file named mincho.tex with the following two lines of content (I'm using my Mincho font name here, so I can really test if my advice will work):

    \usepackage{xeCJK}
    \setCJKmainfont{YuMincho Medium}
    

    The xeCJK package is required by XeLaTeX for supporting Japanese (and Chinese+Korean) fonts.

  2. Second, add -H mincho.tex to the command line so the above code snippet is included into the LaTeX code generated by Pandoc.

    This is the complete command to convert your Markdown to Beamer-PDF:

    pandoc                   \
       mwe.rmd               \
      -t beamer              \
      -o mwe.pdf             \
      --latex-engine=xelatex \
      -H mincho.tex
    

Result (screenshot):

mwe.pdf (screenshot)

The fonts used by the Beamer-PDF are these:

$ pdffonts mwe.pdf

  name                                type         encoding    emb  sub  uni  objID
  ----------------------------------- ------------ ----------- --- ----- ---- -----
  TZVOMD+LMSans8-Regular-Identity-H   CID Type 0C  Identity-H  yes  yes  yes   7  0
  WMSBXQ+LMSans12-Regular-Identity-H  CID Type 0C  Identity-H  yes  yes  yes  30  0
  FXCTKJ+LMSans10-Regular-Identity-H  CID Type 0C  Identity-H  yes  yes  yes  32  0
  NXJKDD+YuMin-Medium-Identity-H      CID Type 0C  Identity-H  yes  yes  no   34  0