Asymptote 和 lualatex 中的字体问题

Asymptote 和 lualatex 中的字体问题

我正在尝试在渐近线中绘制一个 3-d 图形。我使用 Arial 字体作为文本以及数学字母。我正在使用命令编译文件lualatex mwi-lines.texasy mwi-lines*.asy然后使用命令lualatex mwi-lines.tex。以下是显示问题的 MWI。

\documentclass{article}
\usepackage{asymptote}
\usepackage{ifluatex}
\ifluatex
\makeatletter
\def\asy@input@graphic{%
    \ifASYinline
    \IfFileExists{"\AsyFile.tex"}{%
        \catcode`:=12\relax
        \@@input"\AsyFile.tex"\relax
    }{%
        \PackageWarning{asymptote}{file `\AsyFile.tex' not found}%
    }%
    \else
    \IfFileExists{"\AsyFile.\AsyExtension"}{%
        \ifASYattach
        \ifASYPDF
        \IfFileExists{"\AsyFile+0.pdf"}{%
            \setbox\ASYbox=\hbox{\includegraphics[hiresbb]{\AsyFile+0.pdf}}%
        }{%
            \setbox\ASYbox=\hbox{\includegraphics[hiresbb]{\AsyFile.pdf}}%
        }%
        \else
        \setbox\ASYbox=\hbox{\includegraphics[hiresbb]{\AsyFile.eps}}%
        \fi
        \textattachfile{\AsyFile.\AsyExtension}{\phantom{\copy\ASYbox}}%
        \vskip-\ht\ASYbox
        \indent
        \box\ASYbox
        \else
        \ifASYPDF
        \includegraphics[hiresbb]{\AsyFile.pdf}%
        \else
        \includegraphics[hiresbb]{\AsyFile.eps}%
        \fi
        \fi
    }{%
        \IfFileExists{"\AsyFile.tex"}{%
            \catcode`:=12
            \@@input"\AsyFile.tex"\relax
        }{%
            \PackageWarning{asymptote}{%
                file `\AsyFile.\AsyExtension' not found%
            }%
        }%
    }%
    \fi
}
\makeatother
\fi
\usepackage{xfakebold}
\usepackage{unicode-math}
\RequirePackage{firamath-otf}
%\setmathfont{Noto Sans Math}
%\setmathfont{TeX Gyre DejaVu Math}[range={\vdots,\ddots,\mdlgblksquare,\overrightarrow}]
%\setmathfont{TeX Gyre DejaVu Math}[Scale=1.1]
\setmathfont{TeX Gyre DejaVu Math}[Scale=1.3,range={\vdots,\ddots,\mdlgblksquare,\overrightarrow,\bigcup,\oplus,\cup,\cap}]
\setmathfont{TeX Gyre DejaVu Math}[Scale=1.3,range={}]
%\setmathfont{Fira Math}[range={\pi}]
\setmainfont{Arial}[Scale=1.1]
%\newfontface\normalsize{Arial}[Scale=1.2]
\setsansfont{Arial}[Scale=MatchLowercase]
\setmathfont{Arial}[Scale=1.1,range=up/{num,Latin,latin}]
\setmathfont{Arial}[Scale=1.1,range=it/{num,Latin,latin}]
\setmathfont{Arial}[Scale=1.1,range=bfup/{num,Latin,latin}]
\setsansfont{Arial}[Scale=MatchLowercase]
\setmonofont{InconsolataN}[Scale=MatchLowercase]
\begin{document}
        \begin{asy}
        settings.outformat = "pdf";
        settings.prc = false;
        import three;
        import bsp;
        unitsize(1cm);
        size(10cm,0);
        currentprojection=orthographic((5,2,6));
        //From Charles Staats's tutorial
        //Direction of a point toward the camera.
        triple cameradirection(triple pt, projection P=currentprojection) {
        if (P.infinity) {
        return unit(P.camera);
        } else {
        return unit(P.camera - pt);
        }
        }
        triple towardcamera(triple pt, real distance=1, projection P=currentprojection) {
        return pt + distance * cameradirection(pt, P);
        }
        draw(O -- 5X,blue+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(blue)));
        draw(O -- 5Y, green+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(green)));
        draw(O -- 5Z, red+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(red)));
        draw(O -- -5X,blue+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(blue)));
        draw(O -- -5Y, green+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(green)));
        draw(O -- -5Z, red+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(red)));
        path3 pl1 = ((5,-5,5) -- (-5,-5,5) -- (-5,5,-5) -- (5,5,-5) -- cycle);
        dot((5,-5,5) ^^ (-5,-5,5) ^^ (-5,5,-5) ^^ (5,5,-5),3+black);
        surface spl1=surface(pl1);
        draw(spl1,yellow+opacity(1),light=nolight);
        dot((5,-5,5) ^^ (-5,-5,5) ^^ (-5,5,-5) ^^ (5,5,-5),3+black);
        draw((5,-4,4) -- (-5,-4,4),black+linewidth(1pt));
        dot((0,-4,4),black+5);
        label("$\mathbf{P_1}$",align=NW,position=towardcamera((0,-4,4)));
        dot((0,4,-4),black+5);
        label("$\mathbf{P_2}$",align=SE,position=towardcamera((0,3,-3)));
        label("$L_2$",align=SW,position=towardcamera((5,4,-4)));
        draw((5,4,-4) -- (-5,4,-4), black+linewidth(1pt));
        path3 pl2 = ((5,5,5) -- (-5,5,5) -- (-5,-5,-5) -- (5,-5,-5) -- cycle);
        surface spl2=surface(pl2);
        draw(spl2,orange+opacity(1),light=nolight);
        path3 pl = ((0,-5,-5) -- (0,5,-5) -- (0,5,5) -- (0,-5,5) -- cycle);
        dot((5,5,5) ^^ (-5,5,5) ^^ (-5,-5,-5) ^^ (5,-5,-5),3+black);
        surface spl=surface(pl);
        draw(spl,lightblue+opacity(1),light=nolight);
        label("$L_1$",align=W,position=towardcamera((5,-4,4)));
        dot((0,4,4),black+5);
        label("$\mathbf{P_3}$",align=W,position=towardcamera((0,4,4)));
        draw((5,4,4) -- (-5,4,4), linewidth(1pt));
        label("$L_3$",align=SE,position=towardcamera((5,4,4)));
        dot((0,1,1),black+5);
        label("$\mathbf{P_4}$",align=W,position=towardcamera((0,1,1)));
        draw((5,1,1) -- (-5,1,1), black+linewidth(1pt));
        label("$L_4$",align=SE,position=towardcamera((5,1,1)));
        label("$y-z=0$",align=SE,position=towardcamera((-5,5,5)));
        label("$y+z=0$",align=SE,position=towardcamera((-5,-5,5)));
                                    \end{asy}
                                    \(\mathbf{P_2}\), \(L_1\)
                            
\end{document}

在输出中,图中的标签不是 Arial 格式的。但是,下面的文本以 Arial 格式显示,没有任何问题。

在此处输入图片描述 如何解决这个问题?

答案1

周围 LaTeX 代码中的字体设置不会自动传输到 Asymptote 代码。如果您检查(这是生成图形时mwi-lines-1.asy唯一能看到的东西),那么您将看不到任何字体命令。asy

settings.tex="lualatex";您可以使用和语句将它们添加到 Asymptote 代码中texpreamble("")。代码片段:

\begin{asy}
        settings.tex="lualatex";
        settings.outformat = "pdf";
        settings.prc = false;
        texpreamble("\usepackage{unicode-math}\setmathfont{TeX Gyre DejaVu Math}\setmathfont{Nimbus Sans}[Scale=1.1,range=up/{num,Latin,latin}]
\setmathfont{Nimbus Sans}[Scale=1.1,range=it/{num,Latin,latin}]
\setmathfont{Nimbus Sans Bold}[Scale=1.1,range=bfup/{num,Latin,latin}]");

我使用了 Nimbus Sans,因为我没有安装 Arial,但它应该是类似的。

请注意,unicode-math您可以使用\symbf而不是来加粗数学。还请注意,您应该使用 范围\mathbf指定 的加粗变体。\setmathfontbfup

完整 MWE

\documentclass{article}
\usepackage{asymptote}
\usepackage{ifluatex}
\ifluatex
\makeatletter
\def\asy@input@graphic{%
    \ifASYinline
    \IfFileExists{"\AsyFile.tex"}{%
        \catcode`:=12\relax
        \@@input"\AsyFile.tex"\relax
    }{%
        \PackageWarning{asymptote}{file `\AsyFile.tex' not found}%
    }%
    \else
    \IfFileExists{"\AsyFile.\AsyExtension"}{%
        \ifASYattach
        \ifASYPDF
        \IfFileExists{"\AsyFile+0.pdf"}{%
            \setbox\ASYbox=\hbox{\includegraphics[hiresbb]{\AsyFile+0.pdf}}%
        }{%
            \setbox\ASYbox=\hbox{\includegraphics[hiresbb]{\AsyFile.pdf}}%
        }%
        \else
        \setbox\ASYbox=\hbox{\includegraphics[hiresbb]{\AsyFile.eps}}%
        \fi
        \textattachfile{\AsyFile.\AsyExtension}{\phantom{\copy\ASYbox}}%
        \vskip-\ht\ASYbox
        \indent
        \box\ASYbox
        \else
        \ifASYPDF
        \includegraphics[hiresbb]{\AsyFile.pdf}%
        \else
        \includegraphics[hiresbb]{\AsyFile.eps}%
        \fi
        \fi
    }{%
        \IfFileExists{"\AsyFile.tex"}{%
            \catcode`:=12
            \@@input"\AsyFile.tex"\relax
        }{%
            \PackageWarning{asymptote}{%
                file `\AsyFile.\AsyExtension' not found%
            }%
        }%
    }%
    \fi
}
\makeatother
\fi
\usepackage{xfakebold}
\usepackage{unicode-math}
\RequirePackage{firamath-otf}
%\setmathfont{Noto Sans Math}
%\setmathfont{TeX Gyre DejaVu Math}[range={\vdots,\ddots,\mdlgblksquare,\overrightarrow}]
%\setmathfont{TeX Gyre DejaVu Math}[Scale=1.1]
\setmathfont{TeX Gyre DejaVu Math}[Scale=1.3,range={\vdots,\ddots,\mdlgblksquare,\overrightarrow,\bigcup,\oplus,\cup,\cap}]
\setmathfont{TeX Gyre DejaVu Math}[Scale=1.3,range={}]
%\setmathfont{Fira Math}[range={\pi}]
\setmainfont{Nimbus Sans}[Scale=1.1]
%\newfontface\normalsize{Nimbus Sans}[Scale=1.2]
\setsansfont{Nimbus Sans}[Scale=MatchLowercase]
\setmathfont{Nimbus Sans}[Scale=1.1,range=up/{num,Latin,latin}]
\setmathfont{Nimbus Sans}[Scale=1.1,range=it/{num,Latin,latin}]
\setmathfont{Nimbus Sans Bold}[Scale=1.1,range=bfup/{num,Latin,latin}]
\setsansfont{Nimbus Sans}[Scale=MatchLowercase]
\setmonofont{InconsolataN}[Scale=MatchLowercase]
\begin{document}
        \begin{asy}
        settings.tex="lualatex";
        settings.outformat = "pdf";
        settings.prc = false;
        texpreamble("\usepackage{unicode-math}\setmathfont{TeX Gyre DejaVu Math}\setmathfont{Nimbus Sans}[Scale=1.1,range=up/{num,Latin,latin}]
\setmathfont{Nimbus Sans}[Scale=1.1,range=it/{num,Latin,latin}]
\setmathfont{Nimbus Sans Bold}[Scale=1.1,range=bfup/{num,Latin,latin}]");
        import three;
        import bsp;
        unitsize(1cm);
        size(10cm,0);
        currentprojection=orthographic((5,2,6));
        //From Charles Staats's tutorial
        //Direction of a point toward the camera.
        triple cameradirection(triple pt, projection P=currentprojection) {
        if (P.infinity) {
        return unit(P.camera);
        } else {
        return unit(P.camera - pt);
        }
        }
        triple towardcamera(triple pt, real distance=1, projection P=currentprojection) {
        return pt + distance * cameradirection(pt, P);
        }
        draw(O -- 5X,blue+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(blue)));
        draw(O -- 5Y, green+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(green)));
        draw(O -- 5Z, red+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(red)));
        draw(O -- -5X,blue+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(blue)));
        draw(O -- -5Y, green+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(green)));
        draw(O -- -5Z, red+linewidth(1pt),arrow=Arrow3(DefaultHead2,emissive(red)));
        path3 pl1 = ((5,-5,5) -- (-5,-5,5) -- (-5,5,-5) -- (5,5,-5) -- cycle);
        dot((5,-5,5) ^^ (-5,-5,5) ^^ (-5,5,-5) ^^ (5,5,-5),3+black);
        surface spl1=surface(pl1);
        draw(spl1,yellow+opacity(1),light=nolight);
        dot((5,-5,5) ^^ (-5,-5,5) ^^ (-5,5,-5) ^^ (5,5,-5),3+black);
        draw((5,-4,4) -- (-5,-4,4),black+linewidth(1pt));
        dot((0,-4,4),black+5);
        label("$\symbf{P_1}$",align=NW,position=towardcamera((0,-4,4)));
        dot((0,4,-4),black+5);
        label("$\symbf{P_2}$",align=SE,position=towardcamera((0,3,-3)));
        label("$L_2$",align=SW,position=towardcamera((5,4,-4)));
        draw((5,4,-4) -- (-5,4,-4), black+linewidth(1pt));
        path3 pl2 = ((5,5,5) -- (-5,5,5) -- (-5,-5,-5) -- (5,-5,-5) -- cycle);
        surface spl2=surface(pl2);
        draw(spl2,orange+opacity(1),light=nolight);
        path3 pl = ((0,-5,-5) -- (0,5,-5) -- (0,5,5) -- (0,-5,5) -- cycle);
        dot((5,5,5) ^^ (-5,5,5) ^^ (-5,-5,-5) ^^ (5,-5,-5),3+black);
        surface spl=surface(pl);
        draw(spl,lightblue+opacity(1),light=nolight);
        label("$L_1$",align=W,position=towardcamera((5,-4,4)));
        dot((0,4,4),black+5);
        label("$\symbf{P_3}$",align=W,position=towardcamera((0,4,4)));
        draw((5,4,4) -- (-5,4,4), linewidth(1pt));
        label("$L_3$",align=SE,position=towardcamera((5,4,4)));
        dot((0,1,1),black+5);
        label("$\symbf{P_4}$",align=W,position=towardcamera((0,1,1)));
        draw((5,1,1) -- (-5,1,1), black+linewidth(1pt));
        label("$L_4$",align=SE,position=towardcamera((5,1,1)));
        label("$y-z=0$",align=SE,position=towardcamera((-5,5,5)));
        label("$y+z=0$",align=SE,position=towardcamera((-5,-5,5)));
                                    \end{asy}
                                    \(\symbf{P_2}\), \(L_1\)
                                    
\end{document}

结果:

在此处输入图片描述

相关内容