为什么此 merriweather 字体 PDF 在 LuaLaTeX 和 XeLaTeX 中的输出不同?

为什么此 merriweather 字体 PDF 在 LuaLaTeX 和 XeLaTeX 中的输出不同?

这是 MWE,使用merriweather

\documentclass{scrbook}

\usepackage{fontspec}
\usepackage{merriweather}
\usepackage{lipsum}

\begin{document}

\lipsum

\end{document}

使用 LuaLaTeX 和 XeLaTeX 分别编译,会产生不同的 PDF 输出。LuaLaTeX 输出(第一段)看起来不错:

在此处输入图片描述

但它是不可搜索的。标记第一个 lipsum 句子并复制它得到:“L orem ip sum do lo rs it amet, consec te tu erad ip is c in ge lit。”

另一方面,XeLaTeX 很好(“Lorem ipsum”被突出显示,因为我在 PDF 阅读器中将其用作搜索项示例。)

在此处输入图片描述

我想了解 LuaLaTeX 发生了什么,并了解是否有简单的方法可以解决这个问题。我以前从未在其他字体上看到过这种行为。

答案1

在 LuaTeX 更新之前,您可以使用 TrueType 版本的字体作为解决方法。如果您的系统上安装了这些版本,则以下软件包merriweather-mod.sty应提供与原始软件包相同的功能,但使用 TrueType 字体来避免错误。

\ProvidesPackage{merriweather-mod}[%
   2023/11/08 (Kubo) Modified support for Merriweather(Sans) fonts for all LaTeX engines. ] 
% this file is a derived work under the terms of the LaTeX Project Public 
% License, being a modification of merriweather.sty 2022/09/20 (Bob Tennent)
% Changes: load truetype rather than opentype fonts to workaround 
% incompatibility with LuaTeX (https://tex.stackexchange.com/q/700598/)
\RequirePackage{ifxetex,ifluatex,textcomp}

\newif\ifmerriweather@otf
\ifxetex
  \merriweather@otftrue
\else\ifluatex
  \merriweather@otftrue
\else  % [pdf]LaTeX
  \merriweather@otffalse
\fi\fi

\newcommand*{\Merriwthr@scale}{1}  % not adjustable
\newcommand*{\MerriwthrSans@scale}{1}
\RequirePackage{xkeyval}
\DeclareOptionX{scaled}{\renewcommand*{\MerriwthrSans@scale}{#1}}
\DeclareOptionX{scale}{\renewcommand*{\MerriwthrSans@scale}{#1}}

\newif\ifmerriweather@rm \merriweather@rmfalse
\newif\ifmerriweather@sf \merriweather@sffalse
\newif\ifmerriweather@sfdefault \merriweather@sfdefaultfalse
\newif\ifmerriweather@rmlight \merriweather@rmlightfalse
\newif\ifmerriweather@sflight \merriweather@sflightfalse
\newif\ifmerriweather@rmblack \merriweather@rmblackfalse
\newif\ifmerriweather@sfblack \merriweather@sfblackfalse
\newif\ifmerriweather@rmlining \merriweather@rmliningfalse
\newif\ifmerriweather@rmtabular \merriweather@rmtabularfalse
\newif\ifmerriweather@sflining \merriweather@sfliningfalse
\newif\ifmerriweather@sftabular \merriweather@sftabularfalse


\DeclareOptionX{sf}{\merriweather@sftrue}
\DeclareOptionX{rm}{\merriweather@rmtrue}
\DeclareOptionX{sfdefault}{\merriweather@sftrue\merriweather@sfdefaulttrue}
\DeclareOptionX{type1}{\merriweather@otffalse}
\DeclareOptionX{light}{\merriweather@rmlighttrue\merriweather@sflighttrue}
\DeclareOptionX{rmlight}{\merriweather@rmlighttrue}
\DeclareOptionX{sflight}{\merriweather@sflighttrue}
\DeclareOptionX{black}{\merriweather@rmblacktrue\merriweather@sfblacktrue}
\DeclareOptionX{rmblack}{\merriweather@rmblacktrue}
\DeclareOptionX{sfblack}{\merriweather@sfblacktrue}
\DeclareOptionX{rmlining}{\merriweather@rmliningtrue}
\DeclareOptionX{rmoldstyle}{\merriweather@rmliningfalse}
\DeclareOptionX{sflining}{\merriweather@sfliningtrue}
\DeclareOptionX{sfoldstyle}{\merriweather@sfliningfalse}
\DeclareOptionX{rmtabular}{\merriweather@rmtabulartrue}
\DeclareOptionX{rmproportional}{\merriweather@rmtabularfalse}
\DeclareOptionX{sftabular}{\merriweather@sftabulartrue}
\DeclareOptionX{sfproportional}{\merriweather@sftabularfalse}


\ProcessOptionsX\relax

\ifmerriweather@otf
  \RequirePackage{fontspec}
\else
  \RequirePackage{fontenc,fontaxes}
\fi

\ifmerriweather@rm\else\ifmerriweather@sf\else
  \merriweather@rmtrue\merriweather@sftrue  % both false -> both true
\fi\fi

\ifmerriweather@otf
  \ifmerriweather@rmlining
    \def\merriweather@figurestyle{Lining}
  \else
    \def\merriweather@figurestyle{OldStyle} 
  \fi
  \ifmerriweather@rmtabular
    \def\merriweather@figurealign{Monospaced} 
  \else
    \def\merriweather@figurealign{Proportional} 
  \fi

  \ifmerriweather@sflining
    \def\merriweathersans@figurestyle{Lining}
  \else
    \def\merriweathersans@figurestyle{OldStyle} 
  \fi
  \ifmerriweather@sftabular
    \def\merriweathersans@figurealign{Monospaced} 
  \else
    \def\merriweathersans@figurealign{Proportional} 
  \fi

  \ifmerriweather@rmlight
    \def\merriweather@regularstyle{Light}
  \else
    \def\merriweather@regularstyle{Regular}
  \fi
  \ifmerriweather@rmblack
    \def\merriweather@boldstyle{Black}
  \else
    \def\merriweather@boldstyle{Bold}
  \fi

  \ifmerriweather@sflight
    \def\merriweathersans@regularstyle{Light}
  \else
    \def\merriweathersans@regularstyle{Regular}
  \fi
  \ifmerriweather@sfblack
    \def\merriweathersans@boldstyle{Black}
  \else
    \def\merriweathersans@boldstyle{Bold}
  \fi
    
\else % type1
  \ifmerriweather@rmlining
    \def\merriweather@figurestyle{LF}
  \else
    \def\merriweather@figurestyle{OsF}
  \fi
  \ifmerriweather@rmtabular
    \def\merriweather@figurealign{T}
  \else
    \def\merriweather@figurealign{}
  \fi
  \ifmerriweather@sflining
    \def\merriweathersans@figurestyle{LF}
  \else
    \def\merriweathersans@figurestyle{OsF}
  \fi
  \ifmerriweather@sftabular
    \def\merriweathersans@figurealign{T}
  \else
    \def\merriweathersans@figurealign{}
  \fi

  \ifmerriweather@rmlight
    \def\mdseries@rm{light}
  \else
    \def\mdseries@rm{m}
  \fi
  \def\seriesdefault{\mdseries@rm}
  \ifmerriweather@rmblack
    \def\bfseries@rm{black}
  \else
    \def\bfseries@rm{b}
  \fi

  \ifmerriweather@sflight
    \def\mdseries@sf{light}
  \else
    \def\mdseries@sf{m}
  \fi
  \def\seriesdefault{\mdseries@sf}
  \ifmerriweather@sfblack
    \def\bfseries@sf{black}
  \else
    \def\bfseries@sf{b}
  \fi

\fi


% Set main and/or sans fonts:
\ifmerriweather@otf

  \defaultfontfeatures{
     Ligatures = TeX ,
     Extension = .ttf ,
  }
  \ifmerriweather@rm
    \ifmerriweather@rmlight
      \ifmerriweather@rmblack
        \setmainfont
            [ Numbers = {\merriweather@figurealign,\merriweather@figurestyle},
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-Black , 
              BoldItalicFont = *-BlackItalic ]
            {Merriweather}
        \newfontfamily\merriweather
            [ Numbers = {\merriweather@figurealign,\merriweather@figurestyle},
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-Black , 
              BoldItalicFont = *-BlackItalic ]
            {Merriweather}
      \else
        \setmainfont
            [ Numbers = {\merriweather@figurealign,\merriweather@figurestyle},
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldItalic ]
            {Merriweather}
        \newfontfamily\merriweather
            [ Numbers = {\merriweather@figurealign,\merriweather@figurestyle},
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-Bold , ]
            {Merriweather}
      \fi
    \else
      \ifmerriweather@rmblack
        \setmainfont
            [ Numbers = {\merriweather@figurealign,\merriweather@figurestyle},
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Black , 
              BoldItalicFont = *-BlackItalic ]
            {Merriweather}
        \newfontfamily\merriweather
            [ Numbers = {\merriweather@figurealign,\merriweather@figurestyle},
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Black , 
              BoldItalicFont = *-BlackItalic ]
            {Merriweather}
      \else
        \setmainfont
            [ Numbers = {\merriweather@figurealign,\merriweather@figurestyle},
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldItalic ]
            {Merriweather}
        \newfontfamily\merriweather
            [ Numbers = {\merriweather@figurealign,\merriweather@figurestyle},
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldItalic ]
            {Merriweather}
      \fi
    \fi
  \fi
  \ifmerriweather@sf
    \ifmerriweather@sflight
      \ifmerriweather@sfblack
        \setsansfont
            [ Numbers = {\merriweathersans@figurealign,\merriweathersans@figurestyle},
              Scale     = \MerriwthrSans@scale ,
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-Black , 
              BoldItalicFont = *-UltraBoldItalic ]  
            {MerriweatherSans}
        \newfontfamily\merriweathersans
            [ Numbers = {\merriweathersans@figurealign,\merriweathersans@figurestyle},
              Scale     = \MerriwthrSans@scale ,
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-Black , 
              BoldItalicFont = *-UltraBoldItalic ]  
            {MerriweatherSans}
      \else
        \setsansfont
            [ Numbers = {\merriweathersans@figurealign,\merriweathersans@figurestyle},
              Scale     = \MerriwthrSans@scale ,
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldItalic ]  
            {MerriweatherSans}
        \newfontfamily\merriweathersans
            [ Numbers = {\merriweathersans@figurealign,\merriweathersans@figurestyle},
              Scale     = \MerriwthrSans@scale ,
              UprightFont    = *-Light ,
              ItalicFont     = *-LightItalic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldItalic ]  
            {MerriweatherSans}
      \fi
    \else
      \ifmerriweather@sfblack
        \setsansfont
            [ Numbers = {\merriweathersans@figurealign,\merriweathersans@figurestyle},
              Scale     = \MerriwthrSans@scale ,
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Black , 
              BoldItalicFont = *-UltraBoldItalic ]  
            {MerriweatherSans}
        \newfontfamily\merriweathersans
            [ Numbers = {\merriweathersans@figurealign,\merriweathersans@figurestyle},
              Scale     = \MerriwthrSans@scale ,
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Black , 
              BoldItalicFont = *-UltraBoldItalic ]  
            {MerriweatherSans}
      \else
        \setsansfont
            [ Numbers = {\merriweathersans@figurealign,\merriweathersans@figurestyle},
              Scale     = \MerriwthrSans@scale ,
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldItalic ]  
            {MerriweatherSans}
        \newfontfamily\merriweathersans
            [ Numbers = {\merriweathersans@figurealign,\merriweathersans@figurestyle},
              Scale     = \MerriwthrSans@scale ,
              UprightFont    = *-Regular ,
              ItalicFont     = *-Italic ,
              BoldFont       = *-Bold , 
              BoldItalicFont = *-BoldItalic ]  
            {MerriweatherSans}
      \fi
    \fi
  \fi
  % grab the \sfdefault in case it changes subsequently:
  \let\merriweathersffamily\sfdefault
  \ifmerriweather@sfdefault
     \renewcommand*\familydefault{\merriweathersffamily}
  \fi
  \newfontfamily\merriweatherlight
      [ Numbers = {\merriweather@figurealign,\merriweather@figurestyle},
        UprightFont    = *-Light ,
        ItalicFont     = *-LightItalic ,
        BoldFont       = *-Light , 
        BoldItalicFont = *-LightItalic ]
      {Merriweather}
  \newfontfamily\merriweathersanslight
      [ Numbers = {\merriweathersans@figurealign,\merriweathersans@figurestyle},
        Scale     = \MerriwthrSans@scale ,
        UprightFont    = *-Light ,
        ItalicFont     = *-LightItalic ,
        BoldFont       = *-Light ,
        BoldItalicFont = *-LightItalic ]  
      {MerriweatherSans}
  \newfontfamily\merriweatherblack
      [ Numbers = {\merriweather@figurealign,\merriweather@figurestyle},
        UprightFont    = *-Black ,
        ItalicFont     = *-BlackItalic ,
        BoldFont       = *-Black , 
        BoldItalicFont = *-BlackItalic ]
      {Merriweather}
  \newfontfamily\merriweathersansblack
      [ Numbers = {\merriweathersans@figurealign,\merriweathersans@figurestyle},
        Scale     = \MerriwthrSans@scale ,
        UprightFont    = *-Black ,
        ItalicFont     = *-UltraBoldItalic ,
        BoldFont       = *-Black ,
        BoldItalicFont = *-UltraBoldItalic ]  
      {MerriweatherSans}

\else % type1

  \ifmerriweather@rm
    \ifmerriweather@rmlight\def\mdseries@rm{l}\else\def\mdseries@rm{m}\fi
    \ifmerriweather@rmblack\def\bfseries@rm{eb}\else\def\bfseries@rm{b}\fi
  \else
    \def\mdseries@rm{m}\def\bfseries@rm{b}
  \fi
  \ifmerriweather@sf
    \ifmerriweather@sflight\def\mdseries@sf{l}\else\def\mdseries@sf{m}\fi
    \ifmerriweather@sfblack\def\bfseries@sf{eb}\else\def\bfseries@sf{b}\fi
  \else
    \def\mdseries@sf{m}\def\bfseries@sf{b}
  \fi



  \def\merriweatherfamily{Merriwthr-\merriweather@figurealign\merriweather@figurestyle}
  \def\merriweathersffamily{MerriwthrSans-\merriweathersans@figurealign\merriweathersans@figurestyle}

  \ifmerriweather@rm
    \renewcommand*\rmdefault{\merriweatherfamily}
  \fi

  \ifmerriweather@sf
    \renewcommand*\sfdefault{\merriweathersffamily}
  \fi

  \ifmerriweather@sfdefault
    \renewcommand*\familydefault{\merriweathersffamily}
  \fi
  
  \renewcommand*\seriesdefault{\mdseries@rm}

  \newcommand*\merriweather{\fontfamily{\merriweatherfamily}\selectfont}
  \newcommand*\merriweathersans{\fontfamily{\merriweathersffamily}\selectfont}
  \newcommand*\merriweatherlight{\fontfamily{\merriweatherfamily}\fontseries{l}\selectfont}
  \newcommand*\merriweathersanslight{\fontfamily{\merriweathersffamily}\fontseries{l}\selectfont}
  \newcommand*\merriweatherblack{\fontfamily{\merriweatherfamily}\fontseries{eb}\selectfont}
  \newcommand*\merriweathersansblack{\fontfamily{\merriweathersffamily}\fontseries{eb}\selectfont}


\fi

% turn off defaults in case other fonts are selected:
\ifmerriweather@otf
  \defaultfontfeatures{}
\fi

\endinput

请注意,如果文件已分发,则许可条款要求重命名,这是明智的,即使没有分发。

相关内容