我的问题很简单。我使用 babel 包,根据语言,我想显示与活动语言相关的内容。因此我使用包xstring
。我的代码如下
\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}
这不管用。有人有主意吗?
提前致谢。
答案1
\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}
答案2
您必须使用\IfStrEq*
,因为返回的字符串\languagename
由 12 个字符的类别代码组成。
\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}
答案3
最后我发现使用
\iflanguage{english}{this is english}
\iflanguage{french}{this is french}
不使用 xstring 包会简单得多。