在 Asymptote 中更改字体

在 Asymptote 中更改字体

我想用几种不同的字体呈现相同的文本,但是当我执行以下操作时:

import settings;
import fontsize;
settings.tex="lualatex";
outformat="pdf";

size(9cm);
defaultpen(fontsize(10pt));
defaultpen(0.1);

texpreamble("\usepackage{fontspec}\setmainfont{Courier New}");
draw(scale(0.1) * texpath("text"));
texreset();
texpreamble("\usepackage{fontspec}\setmainfont{Arial}");
draw(shift(3, 0) * scale(0.1) * texpath("text"));

生成的图片仅包含用 Courier New 编写的文本。如果我将第 11 行和第 13 行更改为:

draw(scale(0.1) * texpath("text1"));
draw(shift(3, 0) * scale(0.1) * texpath("text2"));

文本渲染正确。这是怎么回事?我该如何用不同的字体渲染相同的文本?我在 Windows 7 上使用 TeX Live 2017。相关说明:当我尝试渲染带有标签的文本时,LuaLaTeX 会产生错误,如下所示:

texpreamble("\usepackage{fontspec}\setmainfont{Courier New}");
label("text", (0,0));
texreset();
texpreamble("\usepackage{fontspec}\setmainfont{Arial}");
label("text", (3,0));

错误:

asy -V font_change_test.asy
Process started (PID=4768) >>>
warning [unbounded]: y scaling in picture unboundedThis is LuaTeX, Version 1.0.4 (TeX Live 2017/W32TeX) 
 restricted system commands enabled.
LaTeX2e <2017-04-15>
(using write cache: C:/Users/Computer/.texlive2017/texmf-var/luatex-cache/generic)(using read cache: C:/texlive/2017/texmf-var/luatex-cache/generic C:/Users/Computer/.texlive2017/texmf-var/luatex-cache/generic)
luaotfload | main : initialization completed in 0.157 secondsBabel <3.15> and hyphenation patterns for 1 language(s) loaded.

(./font_change_test_.tex (c:/texlive/2017/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(c:/texlive/2017/texmf-dist/tex/latex/base/size12.clo(load luc: C:/Users/Comput
er/.texlive2017/texmf-var/luatex-cache/generic/fonts/otl/lmroman12-regular.luc)
)) (c:/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec.sty
(c:/texlive/2017/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
(c:/texlive/2017/texmf-dist/tex/latex/l3kernel/expl3.sty
(c:/texlive/2017/texmf-dist/tex/latex/l3kernel/expl3-code.tex)
(c:/texlive/2017/texmf-dist/tex/latex/l3kernel/l3pdfmode.def)))
(c:/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec-luatex.sty
(c:/texlive/2017/texmf-dist/tex/latex/base/fontenc.sty
(c:/texlive/2017/texmf-dist/tex/latex/base/tuenc.def))
(c:/texlive/2017/texmf-dist/tex/latex/fontspec/fontspec.cfg)(load luc: C:/Users
/Computer/.texlive2017/texmf-var/luatex-cache/generic/fonts/otl/lmroman12-bold.
luc)(load luc: C:/Users/Computer/.texlive2017/texmf-var/luatex-cache/generic/fo
nts/otl/lmroman12-italic.luc)))(load luc: C:/Users/Computer/.texlive2017/texmf-
var/luatex-cache/generic/fonts/otl/arial.luc)(load luc: C:/Users/Computer/.texl
ive2017/texmf-var/luatex-cache/generic/fonts/otl/arialbi.luc)(load luc: C:/User
s/Computer/.texlive2017/texmf-var/luatex-cache/generic/fonts/otl/arialbd.luc)(l
oad luc: C:/Users/Computer/.texlive2017/texmf-var/luatex-cache/generic/fonts/ot
l/ariali.luc) (c:/texlive/2017/texmf-dist/tex/latex/graphics/graphicx.sty
(c:/texlive/2017/texmf-dist/tex/latex/graphics/keyval.sty)
(c:/texlive/2017/texmf-dist/tex/latex/graphics/graphics.sty
(c:/texlive/2017/texmf-dist/tex/latex/graphics/trig.sty)
(c:/texlive/2017/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(c:/texlive/2017/texmf-dist/tex/latex/graphics-def/luatex.def)))
(c:/texlive/2017/texmf-dist/tex/latex/graphics/color.sty
(c:/texlive/2017/texmf-dist/tex/latex/graphics-cfg/color.cfg))
! Undefined control sequence.
<recently read> \pdfpagewidth 

l.24 \pdfpagewidth
                =251.189971bp

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.24 \pdfpagewidth=
                 251.189971bp
! Undefined control sequence.
l.28 \pdfpageheight
                 =9.680209bp
(./font_change_test_.aux)
(c:/texlive/2017/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (c:/texlive/2017/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(c:/texlive/2017/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(c:/texlive/2017/texmf-dist/tex/latex/oberdiek/grfext.sty
(c:/texlive/2017/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty
(c:/texlive/2017/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)))
(c:/texlive/2017/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(c:/texlive/2017/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(c:/texlive/2017/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(c:/texlive/2017/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))
(c:/texlive/2017/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(c:/texlive/2017/texmf-dist/tex/generic/oberdiek/ifpdf.sty))
(c:/texlive/2017/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg)) [1{c:/texl
ive/2017/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./font_change_test_.aux))
(see the transcript file for additional information)
 386 words of node memory still in use:
   3 hlist, 1 vlist, 1 rule, 2 glue, 4 attribute, 49 glue_spec, 4 attribute_lis
t, 1 write nodes
   avail lists: 2:45,3:3,4:6,5:26,6:34,7:18,8:1,9:19
<c:/Windows/fonts/arial.ttf>
Output written on font_change_test_.pdf (1 page, 16115 bytes).
Transcript written on font_change_test_.log.

C:/texlive/2017/texmf-dist\asymptote/plain_shipout.asy: 87.10: runtime: shipout failed
C:\texlive\2017\bin\win32\runscript.tlu:708: command failed with exit code 1:
asy -V font_change_test.asy
<<< Process finished (PID=4768). (Exit code 1)
================ READY ================

答案1

...这是我对 xelatex 的 MWE,遵循说明这里

\documentclass{standalone}
\usepackage{asymptote}
\begin{document}
\begin{asy}
import settings;
import fontsize;
//settings.tex="lualatex";
outformat="pdf";

size(9cm);
defaultpen(fontsize(10pt));
defaultpen(0.1);

texpreamble("\usepackage{fontspec}\setmainfont{Courier New}");
texpreamble("\newfontfamily\myfont{Arial}");
draw(scale(0.1) * texpath("text"));
draw(shift(3, 0) * scale(0.1) * texpath("{\myfont text}"));
\end{asy}
\end{document}

在此处输入图片描述

如果你编译

import settings;
import fontsize;
settings.tex="lualatex";
outformat="pdf";

size(9cm);
defaultpen(fontsize(10pt));
defaultpen(0.1);

texpreamble("\usepackage{fontspec}\setmainfont{Courier New}");
texpreamble("\newfontfamily\myfont{Arial}");
draw(scale(0.1) * texpath("text"));
draw(shift(3, 0) * scale(0.1) * texpath("{\myfont text}"));

使用asy -V,正如您所做的那样。

相关内容