執行 ling-macros 套件時如何解決「命令 \f 已定義」錯誤

執行 ling-macros 套件時如何解決「命令 \f 已定義」錯誤

我正在排版我的論文(語言學),它在 XeLaTeX 中運行良好,直到我使用該ling-macros包,它應該工作正常,因為它不是一個新包,而且我沒有發現關於我遇到的錯誤的類似問題。這就是我得到的:

    > ! LaTeX Error: Command \f already defined.
    >                Or name \end... illegal, see p.192 of the manual.
    > 
    > See the LaTeX manual or LaTeX Companion for explanation. Type  H
    > <return>  for immediate help.  ...                                    
    > 
    >                                                    l.235 \newcommand{\f}[1]{\ensuremath{#1}}
    >                                           ^^I^^I^^I^^I^^I^^I% Formal express...
    > 
    > ?

ling-macros我確信這與(或與我使用的其他一些軟體包衝突?)有關,因為這是我收到的非常具體的訊息;當我%'ed該行時,文件再次運行良好(請參見下面的最後一行)。

以下是我的序言:

\documentclass[12pt]{article}
\usepackage[hmargin=2.5cm, vmargin=2.5cm]{geometry}
\setlength\parindent{4ex}
\setlength\parskip{0pt}
\usepackage{setspace}
\doublespace
\usepackage{fontspec}
\setmainfont{Times New Roman}
\defaultfontfeatures{Scale=MatchLowercase}
\usepackage{polyglossia}

\usepackage[rm, bf]{titlesec} % formatting taken out for brevity

\usepackage{longtable}

\usepackage{natbib}

\usepackage{fancyhdr} % actual header taken out
\pagestyle{fancy}

\usepackage{titling} % actual title with author info taken out

\usepackage{linguex}
\usepackage{tikz-qtree}
\usepackage{ling-macros}

答案1

linguex包定義\f為 的別名\b。也\b被賦予了與標準 LaTeX 不同的意義(即「下劃線」重音)。

在 的上下文中linguex,在\ex.一個輸入中輸入\a.\b.用於介紹項目。該套裝還提供\c. \d. \e. \f.了更多物品。

您可以透過兩種方式解決該問題。一種是相當激烈的,即消除使用\f.for items inside的可能性\ex.:只需添加\let\f\relaxbefore \usepackage{ling-macros}

如果你想使用\f.裡面的物品\ex.,你需要一個更複雜的技巧,如下所示。

\documentclass[12pt]{article}

%% packages

\usepackage[hmargin=2.5cm, vmargin=2.5cm]{geometry}
\usepackage{setspace}
\usepackage{fontspec}
\usepackage{polyglossia}
\usepackage[rm, bf]{titlesec} % formatting taken out for brevity
\usepackage{longtable}
\usepackage{natbib}
\usepackage{fancyhdr} % actual header taken out
\usepackage{titling} % actual title with author info taken out

\usepackage{linguex}
\usepackage{tikz-qtree}

%% fix the issues with \f
\let\f\relax % remove the definition done by linguex
\usepackage{ling-macros} % load the package
\makeatletter
\let\lingmacros@f\f
\DeclareRobustCommand{\f}{\@ifnextchar.\b\lingmacros@f}
\makeatother

%% settings

\setmainfont{Times New Roman}
\defaultfontfeatures{Scale=MatchLowercase}

\pagestyle{fancy}
\doublespacing % not \doublespace
% you don't know what ex is, until at begin document
\AtBeginDocument{\setlength\parindent{4ex}}
% leave a little flexibility to \parskip
%\setlength\parskip{0pt}

我將包加載部分與設定部分分開。請注意,這\doublespace不是正確的聲明,應該是\doublespacing.

相關內容