1

I use this document class abntex2 from: https://ctan.org/pkg/abntex2?lang=en, but when I generate this:

\documentclass[12pt]{abntex2}

\renewcommand{\listfigurename}{Lista de Figuras}

\begin{document}

    \listoffigures*

\end{document}

The list of figures name is not overwritten by Lista de Figuras, it still Lista de Ilustrações:

enter image description here

It only works if I put \renewcommand{\listfigurename}{Lista de Figuras} inside the document like this:

\documentclass[12pt]{abntex2}

\begin{document}

    \renewcommand{\listfigurename}{Lista de Figuras}
    \listoffigures*

\end{document}

enter image description here

Why I cannot override it?

Looking at the abntex2 code, I see they redefine the command:

  1. https://github.com/abntex/abntex2/blob/master/tex/latex/abntex2/abntex2.cls#L163
  \renewcommand{\listfigurename}{Lista de ilustra\c{c}\~{o}es}

How to override the \listfigurename on my preamble, after the abntex class inclusion?


Extra

If someone is wondering how I switch between English and Portuguese this is how:

\documentclass[12pt]{abntex2}
\usepackage[utf8]{inputenc}
\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}}

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

\end{document}

Which generates the following PDF in Portuguese:

enter image description here

If I uncomment the \englishtrue, then, the generated PDF document will be in English as follows: enter image description here

  • 1
    Which language do you use, do you use babel? – Mensch Apr 1 at 4:24
  • 2
    Probably you want: \addto\captionsbrazil{\renewcommand{\listfigurename}{My List}}. – David Purton Apr 1 at 4:36
  • I use english and portuguese for babel with \newcommand{\lang}[2]{\ifenglish#1\else#2\fi}: Is it possible to keep my translation together with original text? - I added this \addto\captionsbrazil on my preamble and it worked. – user Apr 2 at 0:54
1

The problem with your line

\PassOptionsToPackage{brazil,main=english,spanish,french}{babel}

is that it comes to late. At that moment babel was already loaded without that options you need. You need to move the following line above \documentclass{abntex2}

\PassOptionsToPackage{brazil,english}{babel} % ,spanish,french <========

Please see that I deleted spanish and french not used in the mwe and I deletes main=. We change language later with command

\selectlanguage{english}

To show that the code given below works with biblatex too I added an citing and printing of a small bibliography ...

With the complete MWE:

\PassOptionsToPackage{brazil,english}{babel} % ,spanish,french <========
\documentclass[12pt]{abntex2}

\usepackage[utf8]{inputenc}
\usepackage{csquotes}
\usepackage{graphicx}

\newif\ifenglish\englishfalse

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

\ifenglish
  \usepackage[language=english]{biblatex}
  \selectlanguage{english} % <==========================================
\else
  \usepackage[language=brazil]{biblatex}
  \selectlanguage{brazil} % <===========================================
\fi
\addbibresource{biblatex-examples.bib}


\begin{document}

\listoffigures*

\section{\lang{English Section}{Seção em Português}}
\begin{figure}[htbp]
  \centering
  \includegraphics[width=5cm]{example-image-a}
  \caption{test}
  \label{fig:example-image-a}
\end{figure}


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

\begin{figure}[htbp]
  \centering
  \includegraphics[width=5cm]{example-image-b}
  \caption{test b}
  \label{fig:example-image-b}
\end{figure}

\cite{knuth:ct,companion}
\printbibliography

\end{document}

gives us the result:

text

and bibliography

bibliography

If you want to change the usual used titles/names by babel please have a look to this anwer. It shows how you can for example change the brazil name for \listfigurename:

\addto\captionsbrazil{%
  \renewcommand{\listfigurename}{Lista de ilustra\c{c}\~{o}es}%
}

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.