4

I'd like to remove the white space (before and after) when I use \selectlanguage{lang}

\documentclass[10pt, english, brazil]{abntex2}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\providecommand{\printertitle}{}

\addto\captionsenglish{% ingles
    \renewcommand{\printertitle}{Model of theses and dissertations in LaTeX of the ICMC}%
}
\addto\captionsbrazil{% portugues-brasil
    \renewcommand{\printertitle}{Modelo de teses e dissertações em LaTeX do ICMC}%
}

\begin{document}

\begin{resumo}[Abstract]
ANTONELLI, H. L..
\begin{otherlanguage}{english}\printertitle\end{otherlanguage}. 2016. 
81 p. Tese (Doutorado em Ciências – Ciências de Computação e 
Matemática Computacional) – Instituto de Ciências Matemáticas 
e de Computação (ICMC/USP), São Carlos – SP, 2016.
\end{resumo}

\end{document}

This code insert a big white space before and after de text.

For instance:

enter image description here

2 Answers2

2

You should use the otherlanguage environment.

\documentclass[letterpaper,10pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,brazil]{babel}

\providecommand{\printertitle}{}

\addto\captionsenglish{% ingles
    \renewcommand{\printertitle}{Model of theses and dissertations in LaTeX of the ICMC}%
}
\addto\captionsbrazil{% portugues-brasil
    \renewcommand{\printertitle}{Modelo de teses e dissertações em LaTeX do ICMC}%
}

\begin{document}

ANTONELLI, H. L..
\begin{otherlanguage}{english}\printertitle\end{otherlanguage}. 2016. 
81 p. Tese (Doutorado em Ciências – Ciências de Computação e 
Matemática Computacional) – Instituto de Ciências Matemáticas 
e de Computação (ICMC/USP), São Carlos – SP, 2016.

ANTONELLI, H. L..
\printertitle. 2016. 
81 p. Tese (Doutorado em Ciências – Ciências de Computação e 
Matemática Computacional) – Instituto de Ciências Matemáticas 
e de Computação (ICMC/USP), São Carlos – SP, 2016.

\end{document}

enter image description here

A simpler method if you just need two languages:

\documentclass[letterpaper,10pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,brazil]{babel}

\newcommand{\printertitle}{%
  \iflanguage{english}
   {Model of theses and dissertations in LaTeX of the ICMC}%
   {Modelo de teses e dissertações em LaTeX do ICMC}%
}

\begin{document}

ANTONELLI, H. L..
\foreignlanguage{english}{\printertitle}. 2016.
81 p. Tese (Doutorado em Ciências – Ciências de Computação e
Matemática Computacional) – Instituto de Ciências Matemáticas
e de Computação (ICMC/USP), São Carlos – SP, 2016.

ANTONELLI, H. L..
\printertitle. 2016.
81 p. Tese (Doutorado em Ciências – Ciências de Computação e
Matemática Computacional) – Instituto de Ciências Matemáticas
e de Computação (ICMC/USP), São Carlos – SP, 2016.

\end{document}

Another method, rather flexible, for more than two languages; you do

\definelanguagevariable{<command>}
  {
   {<language 1>}{<text 1>}
   {<language 2>}{<text 2>}
   ...
   {<language n>}{<text n>}

and then call either <command> or <command>[<language>]. Without the optional argument the text corresponding to the current language is used; the optional argument will use the stated language.

In the example below, \printertitle will print the Portuguese text, \printertitle[english] the English text; but \printertitle after `\selectlanguage{french} prints the French text.

\documentclass[letterpaper,10pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,french,brazil]{babel}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\definelanguagevariable}{mm}
 {
  \NewDocumentCommand{#1}{o}
   {
    \str_case_x:nn { \IfNoValueTF{##1}{\languagename}{##1} } { #2 }
   }
 }
\ExplSyntaxOff

\definelanguagevariable{\printertitle}
 {
  {brazil}{Modelo de teses e dissertações em \LaTeX{} do ICMC}
  {english}{Model of theses and dissertations in \LaTeX{} of the ICMC}
  {french}{Model pour th\`eses et dissertations en \LaTeX{} de l'ICMC}
 }

\begin{document}

ANTONELLI, H. L..
\printertitle. 2016. 
81 p. Tese (Doutorado em Ciências – Ciências de Computação e 
Matemática Computacional) – Instituto de Ciências Matemáticas 
e de Computação (ICMC/USP), São Carlos – SP, 2016.

ANTONELLI, H. L..
\printertitle[english]. 2016. 
81 p. Tese (Doutorado em Ciências – Ciências de Computação e 
Matemática Computacional) – Instituto de Ciências Matemáticas 
e de Computação (ICMC/USP), São Carlos – SP, 2016.

\selectlanguage{french}
ANTONELLI, H. L..
\printertitle. 2016. 
81 p. Tese (Doutorado em Ciências – Ciências de Computação e 
Matemática Computacional) – Instituto de Ciências Matemáticas 
e de Computação (ICMC/USP), São Carlos – SP, 2016.

\end{document}

enter image description here

egreg
  • 1,121,712
  • 1
    I had tried the first option (otherlanguage), but the problem is the same... Unfortunately, I don't know why this happened. About the second option, I don't have only two languages. =/ – Humberto Lidio Antonelli Oct 06 '16 at 13:25
  • @HumbertoLidioAntonelli The second example can also be used with more languages, \newcommand{\printertitle}{% \iflanguage{english}{Model of theses and dissertations in LaTeX of the ICMC}{}% \iflanguage{french}{bonjour}{}% \iflanguage{portuguese}{Modelo de teses e dissertações em LaTeX do ICMC}% } – samcarter_is_at_topanswers.xyz Oct 06 '16 at 14:57
0

You can use \hspace{acm} where a can be negative or positive depending upon whether you want to shrink the space or expand. For example \hspace{-2cm} shrinks the space by 2 cm.