How do I convert a Markdown document with Japanese to Beamer? - macos

For example, I have this Markdown document:
## Markdown test
Japanese 日本語
I run:
pandoc mwe.rmd -t beamer -o mwe.pdf --latex-engine=xelatex -V mainfont=MS\ Mincho
The words 日本語 simply disappeared in the resulted file. If I don't use the Beamer template then it works correctly.
I don't have to use pandoc. Anything that gets me from Markdown to PDF (slides) on a Mac (with MacTex) would work for me.
If there is no easy solution, I'd be okay with anything that results in non-Beamer PDF slides.

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)
Start Font Book.app.
Type mincho into the top right search box.
All installed fonts with 'Mincho' in their names show up.
Click on one of the font faces (NOT the main entry!) in the list.
A font sample will be displayed.
Click on the button with the little i-logo.
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:
2. fc-list (command line utility)
fc-list is a command line utility that is available via the MacPorts fontconfig package.
If you have it installed, use it.
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"
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:
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.
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):
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

Related

How to use custom fonts in Ghostscript/PostScript?

I convert a PostScript file to PDF by Ghostscript. I have a problem embedding/installing Type 1 fonts.
For installing Type 1 Font, I can add the PFA file path to Ghostscript Fontmap, which should be in /usr/share/ghostscript/version/FONTMAP, but I have no such file in /usr/share/ghostscript/9.50` or similar folders on Ubuntu 20.04.
How can I include the font file directly within the script:
Instead of
/Times-Bold findfont 10 scalefont setfont
something like
(/home/font.pfa) 10 scalefont setfont
Does PostScript/Ghostscript use AFM file data or read the glyph widths or just from the glyph structure provided in PFA file?
The fonts and Fontmap file can be placed in several directories. Here is a typical search path:
/usr/share/ghostscript/9.52/Resource/Init/Fontmap
/usr/share/ghostscript/9.52/lib/Fontmap
/usr/share/ghostscript/9.52/Resource/Font/Fontmap
/usr/share/ghostscript/fonts/Fontmap
/usr/share/fonts/Type1/Fontmap
/usr/share/fonts/Fontmap
I sometimes use fonts that are not installed in the search path just in the current working directory. I use the gs -P and either of these work:
(font.pfa) 12 selectfont
/font.pfa 12 selectfont
The search path can also be modified by adding the directories to the GS_FONTPATH or GS_LIB environment variables.
The AFM file is not mandatory and the metrics can be obtained from the font alone. Some programs use the AFM file instead of the actual fonts and so they are needed for those programs.
You do, you just have the path/name slightly wrong:
/usr/share/ghostscript/9.50/Resource/Init/Fontmap.GS
You can also use your own custom fontmap using a command line parameter: "-sFONTMAP=/path/to/custom/fontmap" (best to copy the system one, and add your customisations to the copy)
You can't, not like that, anyway - that's not how Postscript works. Postscript always references fonts by name (not by file/path), so whilst there ways to read the font file(s), you still need to know the font name(s) in order to scale and set the font(s).
Ghostscript does not use AFM files, it gets the metrics from the fonts and glyph outlines.
Hope that helps some....

Why won't Ghostscript recognize my modified 'cidfmap' file?

I'm attempting to use Ghostscript 9.27 on Windows 10 Pro to compress a PDF with CID fonts, using a modified 'cidfmap' file ($GS_HOME/Resource/Init/cidfmap). However, Ghostscript doesn't seem to recognize my changes to 'cidfmap', and instead wants to load the DroidSansFallback TrueType font to emulate the missing CID font.
I have tried using the "-I" command line parameter to tell Ghostscript to use the modified file in the $GS_HOME/Resource/Init directory, as specified in the documentation.
I've also tried building the source code within Developer Command Prompt for VS 2017, using the following command (and no errors):
nmake /A psi/msvc.mak MSVC_VERSION=15 WIN64=
Below is the full Ghostscript command I am running in the command prompt:
gswin64c.exe -I"C:/Program Files/gs/ghostscript-9.27/Resource/Init" -sDEVICE=pdfwrite -dPDFSETTINGS=/printer -dPDFSTOPONERROR -dBATCH -dNOPAUSE -sOutputFile=output.pdf m0001-062-1.pdf
the record added to the 'cidfmap' file (it's the only one):
/MSPGothic << /FileType /TrueType /Path ("C:/Windows/Fonts/msgothic.ttc") /SubfontID 0 /CSI [(Japan1) 2] >> ;
and the output from Ghostscript I've been receiving in both cases:
GPL Ghostscript 9.27 (2019-04-04)
Copyright (C) 2018 Artifex Software, Inc. All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
Processing pages 1 through 4.
Page 1
Loading NimbusRoman-Bold font from C:/Program Files/gs/ghostscript-9.27/Resource/Font/NimbusRoman-Bold... 4570288 3226611 4074256 2336262 4 done.
Page 2
Page 3
Querying operating system for font files...
Substituting font Helvetica for ArialMT.
Loading NimbusSans-Regular font from C:/Program Files/gs/ghostscript-9.27/Resource/Font/NimbusSans-Regular... 5086792 3742157 2284000 967988 4 done.
Substituting font Helvetica-Narrow for ArialNarrow.
Loading NimbusSansNarrow-Regular font from C:/Program Files/gs/ghostscript-9.27/Resource/Font/NimbusSansNarrow-Regular... 5273304 3930300 2397536 1064531 4 done.
Substituting font Helvetica-Bold for Arial-BoldMT.
Loading NimbusSans-Bold font from C:/Program Files/gs/ghostscript-9.27/Resource/Font/NimbusSans-Bold... 5500440 4150230 3021540 1680111 4 done.
Can't find CID font "MSPGothic".
Attempting to substitute CID font /Adobe-Japan1 for /MSPGothic, see doc/Use.htm#CIDFontSubstitution.
The substitute CID font "Adobe-Japan1" is not provided either. attempting to use fallback CIDFont.See doc/Use.htm#CIDFontSubstitution.
Loading a TT font from C:/Program Files/gs/ghostscript-9.27/Resource/CIDFSubst/DroidSansFallback.ttf to emulate a CID font Adobe-Japan1 ... Done.
Page 4
Can't find CID font "MSPGothic".
Attempting to substitute CID font /Adobe-Japan1 for /MSPGothic, see doc/Use.htm#CIDFontSubstitution.
Loading a TT font from C:/Program Files/gs/ghostscript-9.27/Resource/CIDFSubst/DroidSansFallback.ttf to emulate a CID font Adobe-Japan1 ... Done.
It seems as if I've missed something simple here, as others with similar questions got it working with just the "-I" command line parameter.
What am I doing wrong?
The problem is (once I looked carefully enough!) clear. You've put quotes "" around the filename.
The '(' and ')' characters are string delimiters in PostScript, not " (and the cidfmap file is read as a PostScript program) so by doing that you've made the " characters part of the path. Unsurprisingly Ghostscript can't find a path beginning with "
So if you change your cidfmap entry to:
/MSPGothic << /FileType /TrueType /Path (C:/Windows/Fonts/msgothic.ttc) /SubfontID 0 /CSI [(Japan1) 2] >> ;
you should find it works, it does for me.

How do I force GNU "barcode" to honor the page size I specify on the command line?

history:
I am trying to get GNU "barcode" to produce bar codes that I can add to pick lists, and work orders. I am trying to create the bar-codes as small as the physical labels that we use in the warehouse (2.5"x0.75") using the following command:
#barcode -b 'TEXTTOENCODE' -c -e code39 -u in -g 2.5x0.75 -u in -p 2.5x0.75 > bc.ps
problem:
No matter what page size parameters I use, I only seem to be able to produce US Letter size documents.
When I open the resulting file (in KDE Document Viewer) the file properties are reported as: 'US Letter, Portrait (216 × 279 mm)' as seen below:
KDE Document Viewer - Sample Barcode image with picture properties.
GNU barcode version below:
# barcode --version
barcode frontend (GNU barcode) 0.98
Any suggestions as to what I might be doing wrong, are welcome.
Thanks,
'Skye
You are doing nothing wrong, it's just that barcode uses an obsolete DSC comment to declare paper size, which isn't recognized by the PS viewer. Maybe try using option -E? This will crop the document to just the bar code.

Golang vips: How to render text with custom truetype font?

When we want to render text an vips image, you do something like this with vips_text:
import "C"
var textImage *C.VipsImage
cText := C.CString("Some text")
cFont := C.CString("Arial 12px")
C.cgo_vips_text(&textImage, cText, cFont)
But here, Arial 12px is a fontconfig string name and assumes that the system has this font installed.
How do I let the program use a custom truetype font file, e.g., Roboto.ttf?
Trying
cFont := C.CString("Roboto.ttf")
probably won't work.
We could put the Roboto.ttf file in the system directory, for example, in Ubuntu you put the file in /usr/share/fonts/truetype, but the code makes the assumption that this font exists, which is not a solution to write machine-independent program. So I wonder if there is a better way to do this so that we can ship the executables with the font file together.
vips uses standard fontconfig font names, so you need to set up fontconfig to add your custom font to its search path.
From the manual it looks like you can set the environment variable XDG_CONFIG_HOME to point to your new font, then from go refer to that font as Roboto 48pt (for example).
It's easy to test from the command-line. Try:
$ fc-match "Roboto"
Roboto-Regular.ttf: "Roboto" "Regular"
$ vips text x2.png "hello" --font "Roboto 48px"
$ vips text x.png "hello" --font "Arial 48px"
$ eog x.png x2.png
And make sure you see two different images.

Pandoc: use variables in custom latex preamble

I have the file test.md which contains:
---
footertext: some text for the footer
headertext: this is in the header
---
here is the text body.
And the file format.tex which contains:
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead[L]{$headertext$}
\fancyfoot[L]{$footertext$}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headsep}{0.25in}
I run the command:
pandoc -H format.tex test.md -o test.pdf
You can see what I want to do. I am trying to get the text "this is in the header" to show up in the header, but it does not, it only shows the string "headertext" (same problem for footer).
What am I doing wrong?
Edit: OK, I think I understand. Apparently variables are only available in templates, not in included begin or end code blocks (like I am using), or in the md itself. So new question: Why is this? It is unintuitive, inconvenient, and poorly documented.
You can easily modify a pandoc template. Access the default template with
pandoc -D latex > new_template.latex
Paste the content of your format.tex in the preamble. You should use $if$ to check if the variable exists before using it if you want to use this template for more than one document :
\usepackage{fancyhdr}
\pagestyle{fancy}
$if(headertext)$\fancyhead[L]{$headertext$}$endif$
$if(footertext)$\fancyfoot[L]{$footertext$}$endif$
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\setlength{\headsep}{0.25in}
Then compile with :
pandoc test.md -o test.pdf --template=new_template.latex

Resources