多语言代码和 for 循环

多语言代码和 for 循环

我对@Skillmon 提供的一段代码非常满意,请参见此处

多语言支持 - 需要 xkeyval 方面的帮助

对于处理文档,逐节创建彼此接近的不同语言很有用。然而,最终文档需要所有章节都使用第一种语言,然后所有章节都使用第二种语言,依此类推。当然,章节计数器也需要重置。

我尝试用一​​个简单的 for 循环来实现这一点,但没有成功

\documentclass{scrartcl}
\usepackage{multilanguage}
\usepackage{multiaudience}
\usepackage{pgffor}

\SetNewAudience{intern}
\SetNewAudience{extern}
\DefCurrentAudience{intern,extern}

\SetNewLanguages{DE,EN}

\begin{document}
\foreach \langlooper in {DE,EN}{
\newpage
\DefCurrentLanguage{\langlooper}
\setcounter{section}{0}

\section{Erstens}
\lang{DE}{THIS IS GERMAN\\
\showto{intern} {DE: INTERN TEXT}\\
\showto{extern}{DE: EXTERN TEXT}\\
}
\lang{EN}{THIS IS ENGLISH\\
\showto{intern} {EN: INTERN TEXT}\\
\showto{extern}{EN: EXTERN TEXT}\\
}

\lang{DE}{\section{GERMAN SECTION}}
\lang{EN}{\section{ENGLISH SECTION}}


new try

\mlsection{DE=German Section, EN=English Section, default=FALLBACK TITLE, label=sec:multilang}

\begin{langen}{DE}
THIS PARAGRAPH IS GERMAN.

THIS, TOO
\end{langen}

\begin{langen}{EN}
THIS PARAGRAPH IS ENGLISH.

THIS, TOO
\end{langen}

\mlsubsection{DE=German Subsection, EN=English Subsection,}
See section~\ref{sec:multilang}.

See in figure \ref{fig:fig2}

\begin{figure}
\centering{
An EXAMPLE
}
\caption{\lang{EN}{A caption} \lang{DE}{Eine Bildunterschrift}}
\label{fig:label1}
\end{figure}

\begin{figure}
\centering{
An EXAMPLE
}
\mlcaption{DE=Eine Bildunterschrift, EN=A caption, label=fig:fig2}
\end{figure}
}
\end{document}

似乎 \langlooper 键没有被正确用作参数有什么提示吗?

谢谢乔治

PS:这是multilanguage.sty的代码

%% LaTeX2e file `multilanguage.sty'
%% generated by the `filecontents' environment
%% from source `test3' on 2023/09/11.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{multilanguage}
[2023/09/08 v1.0 Some tests]

\RequirePackage{expkv}

\providecommand*\CurrentLanguage{}

\protected\def\DefCurrentLanguage
  {%
    \@MULTLANG@deactivate
    \ekvcsvloop\@MULTLANG@activate
  }
\protected\def\@MULTLANG@activate#1%
  {%
    \expandafter\let
      \csname @MULTLANG@@iflang@\detokenize{#1}\endcsname
      \@firstoftwo
  }

\newcommand\@MULTLANG@deactivate{}

\protected\def\SetNewLanguages{\ekvcsvloop\@MULTLANG@new@language}
\protected\def\@MULTLANG@new@language#1%
  {%
    \@ifundefined{@MULTLANG@@iflang@\detokenize{#1}}%
      {%
        % add it to the list of languages which need to be deactivated on
        % language change
        \edef\@MULTLANG@deactivate
          {%
            \unexpanded\expandafter{\@MULTLANG@deactivate}%
            \unexpanded\expandafter
              {%
                \expandafter\let
                  \csname @MULTLANG@@iflang@\detokenize{#1}\endcsname
                  \@secondoftwo
              }%
          }%
        % init the language
        \expandafter\let
          \csname @MULTLANG@@iflang@\detokenize{#1}\endcsname
          \@secondoftwo
      }%
      {%
        \PackageError{multilanguage}%
          {Language `\detokenize{#1}' already defined.}{}%
      }%
  }

\def\lang#1%
  {%
    \@ifundefined{@MULTLANG@@iflang@\detokenize{#1}}%
      {%
        % expandable error message
        \ekverr{multilanguage}{Unknown language `#1'}%
        \@gobble
      }%
      {%
        \csname @MULTLANG@@iflang@\detokenize{#1}\endcsname
          \@firstofone
          \@gobble
      }%
  }
  
\RequirePackage{environ}
\NewEnviron{langen}[1]{%
 \lang{#1}{\BODY}} 

\ekvsetdef\@MULTLANG@section@keys{MULTLANG/section}
% keep in mind that the key will be used in an expanded-context, so we use
% \unexpanded
\ekvdef{MULTLANG/section}{label}{\unexpanded{\label{#1}}}
% default will only be used if no other language was used before it
\ekvdef{MULTLANG/section}{default}
  {%
    \ifcsname @MULTLANG@@flag@notfirst\endcsname
      \expandafter\@gobble
    \else
      \expandafter\@gobble\csname @MULTLANG@@flag@notfirst\endcsname
      \expandafter\@firstofone
    \fi
    {\unexpanded{#1}}%
  }
% every unknown key will be interpreted as a language key
\ekvdefunknown{MULTLANG/section}
  {%
    \lang{#2}
      {%
        \ifcsname @MULTLANG@@flag@notfirst\endcsname
          \space/\space
        \else
          \expandafter\@gobble\csname @MULTLANG@@flag@notfirst\endcsname
        \fi
        \unexpanded{#1}%
      }%
  }

\def\mlsection#1%
  {%
    % group to keep the notfirst-flag local
    \begingroup
      \expandafter\section\expanded
        {{\@MULTLANG@section@keys{#1}}}%
    \endgroup
  }
 \def\mlsubsection#1%
  {%
    % group to keep the notfirst-flag local
    \begingroup
      \expandafter\subsection\expanded
        {{\@MULTLANG@section@keys{#1}}}%
    \endgroup
  }
\def\mlsubsubsection#1%
  {%
    % group to keep the notfirst-flag local
    \begingroup
      \expandafter\subsubsection\expanded
        {{\@MULTLANG@section@keys{#1}}}%
    \endgroup
  }
\def\@MULTLANG@missing@value#1%
  {%
    \ekvifdefinedNoVal{#1}{\@MULTLANG@section@keys{#1}}%
      {\ekverr{multilanguage}{Missing value for `#1'}}%
  }
\def\@MULTLANG@mlsection#1#2%
  {%
    \ekvifdefined{MULTLANG/section}{#1}{\@MULTLANG@section@keys{{#1}={#2}}}%
    \lang{#1}
      {%
        \ifcsname @MULTLANG@@flag@notfirst\endcsname
          \space/\space
        \else
          \expandafter\@gobble\csname @MULTLANG@@flag@notfirst\endcsname
        \fi
        \unexpanded{#2}%
      }%
  }
  
  
\ekvsetdef\@MULTLANG@caption@keys{MULTLANG/section}
% keep in mind that the key will be used in an expanded-context, so we use
% \unexpanded
\ekvdef{MULTLANG/section}{label}{\unexpanded{\label{#1}}}
% default will only be used if no other language was used before it
\ekvdef{MULTLANG/section}{default}
  {%
    \ifcsname @MULTLANG@@flag@notfirst\endcsname
      \expandafter\@gobble
    \else
      \expandafter\@gobble\csname @MULTLANG@@flag@notfirst\endcsname
      \expandafter\@firstofone
    \fi
    {\unexpanded{#1}}%
  }
% every unknown key will be interpreted as a language key
\ekvdefunknown{MULTLANG/caption}
  {%
    \lang{#2}
      {%
        \ifcsname @MULTLANG@@flag@notfirst\endcsname
          \space/\space
        \else
          \expandafter\@gobble\csname @MULTLANG@@flag@notfirst\endcsname
        \fi
        \unexpanded{#1}%
      }%
  }  
  
\def\mlcaption#1%
  {%
    % group to keep the notfirst-flag local
    \begingroup
      \expandafter\caption\expanded
        {{\@MULTLANG@caption@keys{#1}}}%
    \endgroup
  }

相关内容