4

I want to render the same text with a couple of different fonts, but when I do the following:

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"));

The resulting picture contains text written only in Courier New. If I change lines 11 and 13 to:

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

The text renders correctly. What is going on here, and how can I render the same text with different fonts? I am using TeX Live 2017 on Windows 7. On a related note, LuaLaTeX generates errors when I try to render the text with labels like this:

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

The error:

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 ================
2
  • I guess what you might want to do is, as described here, to introduce a main font as you did, and then use a second font with \newfontfamily\myfont[<font features>]{<name of font>} instead of the texreset();. I checked that this works if I use xelatex. However, I could not test it with lualatex.
    – user121799
    Jan 26, 2018 at 1:44
  • Perhaps related.
    – user121799
    Jan 26, 2018 at 2:17

1 Answer 1

5

... and this is my MWE for xelatex, following the instructions here.

\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}

enter image description here

You obtain the same result if you compile

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}"));

with asy -V, as you did.

7
  • Thank you for your answer. But why does my approach fail? The documentation says that texreset() resets all TeX macros. I'd like to do this switching for a large number of fonts, and this is a little bit of an inconvenient way of doing it. I'll accept your answer if nothing better gets suggested.
    – blaze
    Jan 26, 2018 at 14:05
  • @blaze I guess that this is because \usepackage is not a macro and you can only load it in the document preamble but not within the document.
    – user121799
    Jan 26, 2018 at 14:14
  • I just tried to load the fonts from a list and failed. LuaLaTeX complains: string[] font_names = {"Courier New", "Arial"}; texpreamble("\usepackage{fontspec}"); for (int i = 0; i < font_names.length; ++i) { string preamble = "\newfontfamily\myfont" + (string)i + "{" + font_names[i] +"}"; texpreamble(preamble); draw(shift((i + 1) % 5, -ceil((i + 1) / 5)) * scale(0.1) * texpath("{\myfont" + (string)i + " o}")); }
    – blaze
    Jan 26, 2018 at 14:30
  • @blaze I guess that this is sort of the same problem (but I am by no means an expert). In this case, I'd like to argue that it does not make too much sense to do a loop. If I were to do a loop here, then this would be a loop that writes the asymptote lines along the lines of my answer.
    – user121799
    Jan 26, 2018 at 14:39
  • Can you please give me an example? I tried to follow the same logic as in your answer.
    – blaze
    Jan 26, 2018 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.