![如何在 \IfLanguageName 中使用 \verb - 错误 \verb 以行尾结束。}{}](https://linux22.com/image/412705/%E5%A6%82%E4%BD%95%E5%9C%A8%20%5CIfLanguageName%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20%5Cverb%20-%20%E9%94%99%E8%AF%AF%20%5Cverb%20%E4%BB%A5%E8%A1%8C%E5%B0%BE%E7%BB%93%E6%9D%9F%E3%80%82%7D%7B%7D.png)
我想\verb
在里面使用\IfLanguageName
。但我收到错误消息\verb ended by end of line. ...ame{english}{... \verb| echo Hello | ...}{}
。我想同时只显示一种语言。
\documentclass{article}
\usepackage{iflang}
\begin{document}
\setlanguage{english}
\IfLanguageName{swedish}{... \verb| echo Hello | ...}{}
\IfLanguageName{english}{... \verb| echo Hello | ...}{}
\end{document}
答案1
你可以定义一个环境。通过定义与我们所得到的可管理语法\Stop
相同。\fi
\documentclass{article}
\usepackage[swedish,english]{babel}
\usepackage{iflang}
\makeatletter
\newenvironment{languageswitch}
{\expandafter\let\csname Start@\languagename\endcsname\@empty}
{\ignorespacesafterend}
\newcommand{\Start}[1]{%
\@ifundefined{Start@#1}{\iffalse}{\iftrue\ignorespaces}%
}
\let\Stop\fi
\makeatother
\begin{document}
\section{English}
\begin{languageswitch}
\Start{swedish}
... \verb| echo svenska | ...
\Stop
\Start{english}
... \verb| echo English | ...
\Stop
\end{languageswitch}
\section{Swedish}
\selectlanguage{swedish}
\begin{languageswitch}
\Start{swedish}
... \verb| echo svenska | ...
\Stop
\Start{english}
... \verb| echo English | ...
\Stop
\end{languageswitch}
\end{document}