如何将 babel 字幕添加到 newfloat 包环境中?

如何将 babel 字幕添加到 newfloat 包环境中?

这个最小的例子将产生以下 PDF:

\documentclass[12pt]{abntex2}
\usepackage[utf8]{inputenc}

\usepackage{newfloat}
\DeclareFloatingEnvironment[fileext=loq,placement={!hbtp},
         name=Frame,within=chapter,listname=List of Frames]{board}

% \addto\captionsbrazil{\renewcommand{\boardname}{Quadro}}
% \addto\captionsbrazil{\renewcommand{\listofboardsname}{Lista de Quadros}}

\newif\ifenglish\englishfalse
% \englishtrue
\newcommand{\lang}[2]{\ifenglish#1\else#2\fi}

\ifenglish
    \PassOptionsToPackage{language=english}{biblatex}
    \PassOptionsToPackage{brazil,main=english,spanish,french}{babel}
\else
    \PassOptionsToPackage{language=brazil}{biblatex}
    \PassOptionsToPackage{main=brazil,english,spanish,french}{babel}
\fi

\begin{document}

\section{\lang{English Section}{Seção em Português}}

    \listofboards*

    \lang{Section contents.}{Conteúdo da seção.}

    \begin{board}[htb]
    \centering
    \caption{\lang{Subtitle}{Legenda}}
    \begin{tabular}{|c|}
    \hline
    \lang{Content}{Conteúdo}\\
    \hline
    \end{tabular}
    \fonte{\lang{Author}{Autor}}
    \end{board}

\end{document}

在此处输入图片描述

其中captions和 英语 混杂在一起。如果取消注释这些行\addto\captionsbrazil,Latex 将抛出错误:

LaTeX Error: \listofboardsname undefined.

我曾经\addto\captionsbrazil在另一个问题上使用过类似的东西在我的类使用 renewcommand 重新定义序言中的命令之后,如何覆盖它?,问题就解决了。我该如何将其\addto\captionsbrazilnewfloat刚刚创建的包板环境一起使用?

答案1

读完这个问题后更改包和英国 babel:未定义的控制序列,我设法通过以下方式修复它:

  1. 创建一个命令来保存列表的标题
  2. 使用该命令将列表标题传递给DeclareFloatingEnvironment
  3. 使用\addto\captionsbrazil{\renewcommand{\listofboardsname}
\newif\ifenglish\englishfalse

% \englishtrue
\newcommand{\lang}[2]{\ifenglish#1\else#2\fi}

\ifenglish
    \PassOptionsToPackage{language=english}{biblatex}
    \PassOptionsToPackage{brazil,main=english,spanish,french}{babel}
\else
    \PassOptionsToPackage{language=brazil}{biblatex}
    \PassOptionsToPackage{main=brazil,english,spanish,french}{babel}
\fi

\documentclass[12pt]{abntex2}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{newfloat}
\newcommand\listofboardsname{List of Frames}

\DeclareFloatingEnvironment[fileext=loq,placement={!hbtp},name=Frame,
        within=chapter,listname=\listofboardsname]{board}

\addto\captionsbrazil{\renewcommand{\boardname}{Quadro}}
\addto\captionsbrazil{\renewcommand{\listofboardsname}{Lista de Quadros}}

\begin{document}

\section{\lang{English Section}{Seção em Português}}

    \listofboards

    \lang{Section contents.}{Conteúdo da seção.}

    \begin{board}[htb]
    \centering
    \caption{\lang{Subtitle}{Legenda}}
    \begin{tabular}{|c|}
    \hline
    \lang{Content}{Conteúdo}\\
    \hline
    \end{tabular}
    \fonte{\lang{Author}{Autor}}
    \end{board}

\end{document}

参考:

  1. 为什么 LaTeX 不能对包含重音符号的单词进行连字符连接,例如“développement”?
  2. 从目录中删除 [newfloat] 列表

相关内容