TransWikia.com

Language detection and condition

TeX - LaTeX Asked on February 19, 2021

My problem is quite simple. I use the babel package and depending on the language I want to display something with respect to the active language. Therefore I use the package xstring. My code is the following

documentclass[10pt]{article}
usepackage{xstring}
usepackage[french,english]{babel}

begin{document}
selectlanguage{french}

languagename%show the string

IfStrEq{languagename}{french}{Yes, it's french!}{No, it's not french!}

end{document}  

This does not work. Anyone an idea?

Thanks in advance.

3 Answers

Finally I found that using

iflanguage{english}{this is english}

iflanguage{french}{this is french}

is far more simple without using the xstring package.

Answered by Willi on February 19, 2021

You have to use IfStrEq*, because the string returned by languagename consists of category code 12 characters.

documentclass[10pt]{article}
usepackage{xstring}
usepackage[french,english]{babel}

begin{document}

languagename%show the string

IfStrEq*{languagename}{french}{Yes, it's french!}{No, it's not french!}

selectlanguage{french}

languagename%show the string

IfStrEq*{languagename}{french}{Yes, it's french!}{No, it's not french!}

end{document}

enter image description here

Answered by egreg on February 19, 2021

The minimal example with the iflang solution of Javier Bezos would be:

documentclass[10pt]{article}
usepackage{iflang}
usepackage[french,english]{babel}

begin{document}
    
    title{%
        IfLanguageName{french}{Yes, it's french!}{No, it's not french!}%
        
        selectlanguage{french}%
        IfLanguageName{french}{Yes, it's french!}{No, it's not french!}%
    }
end{document}

enter image description here

Answered by Scotty on February 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP