18

I am currently preparing the presentation for my internship evaluation. As a French student evaluated by researchers that may or may not speak French, I would like to maintain two versions of my presentation, in French and in English.

I could just create two separate files but I am pretty sure that maintaining both of them would be complicated and that I would most likely forget to port corrections from any version to the other one as well. Thus, my preferred option would be to keep them in the same file (files, in fact: I have taken the habit of having separate files for each section of my documents and \include them all in at the end).

Here is a MWE showing how I managed to do it :

\documentclass{beamer}


\usepackage[T1]{fontenc}
\usepackage[english, french]{babel}
\usepackage{etoolbox}
\usepackage{blindtext}

%\includeonlylecture{english}
%\includeonlylecture{french}

\newcommand{\switch}[1]{%Use with "french" or "english" to switch between languages
%Security check
\ifstrequal{#1}{french}%
{}%
{\ifstrequal{#1}{english}%
    {}%
    {\PackageError{switch}{Invalid input}{Received "#1" instead of "french" or "english"}}%
}
\lecture{#1}{#1}
\selectlanguage{#1}
\ifstrequal{#1}{french}%
    {%
    \title{French title}
    }%
    {\ifstrequal{#1}{english}%
        {%
        \title{English title}
        }%
        {}%
    }
}

\begin{document}

\switch{english}
\begin{frame}
\titlepage
\end{frame}

\switch{french}
\begin{frame}
\titlepage
\end{frame}

\switch{english}
\begin{frame}{English frame}
\blindtext
\end{frame}

\switch{french}
\begin{frame}{French frame}
\blindtext
\end{frame}

\end{document}

By using \switch with english or french and selecting the desired output language with \includeonlylecture, I managed to only output the corresponding half of the document.

I felt the need to redefine the title at each switch because the theme I use, JuanLesPins, shows the last title specified at the top of each slide.

My question is: is there a cleaner way to do what I'm trying to do, i.e. preparing two consecutive versions of each slide in two different languages and only output one of them?

Anab
  • 355
  • +1 for keeping all the content in both languages in one file – meduz Jun 30 '15 at 22:15
  • 1
    @MartinSchröder It is indeed a duplicate, thanks. Nevertheless, I'd like to point out that touhami's answer is more complete as it gives two solutions and linked me to another answer that solved the problem with french accentuation when using the comment package. – Anab Jul 01 '15 at 11:46

1 Answers1

8

It's very easy with comment package

\documentclass{beamer}
\usepackage{comment}


 % for english
\includecomment{english}
\excludecomment{french}
%  for french
%\includecomment{french}
%\excludecomment{english}


\begin{french}
\usepackage[french]{babel}
\end{french}

\usepackage{blindtext}


\begin{french}
\title{Titre}
\author{Moi}
\end{french}

\begin{english}
\title{Title}
\author{Me}
\end{english}

\begin{document}

\begin{frame}
\titlepage
\end{frame}

\begin{frame}
\tableofcontents
\end{frame}


\begin{french}
\section{Bon}
\subsection{jour}

\begin{frame}{French frame}
\blindtext 
\end{frame}
\end{french}

\begin{english}

\section{Hellow}
\subsection{world}

\begin{frame}{English frame}
\blindtext 
\end{frame}
\end{english}

\end{document}

Here is the first solution Edited to fill the comment below

\documentclass{beamer}

\newif\iffrenchb 

% uncomment next line for french
%\frenchbtrue

\newcommand{\iffrench}[2]{\iffrenchb #1\else #2\fi}
\newsavebox\efframe

\iffrench{
\usepackage[frenchb]{babel}
}{
\usepackage[english]{babel}
}

\usepackage{blindtext}


\iffrench{
\newenvironment{french}{\begin{frame}}{\end{frame}}
\newenvironment{english}{\begin{lrbox}{\efframe}}{\end{lrbox}}
}{
\newenvironment{english}{\begin{frame}}{\end{frame}}
\newenvironment{french}{\begin{lrbox}{\efframe}}{\end{lrbox}}
}

\iffrench{
\title{Titre}
\author{Moi}
}{
\title{Title}
\author{Me}
}
\begin{document}

\begin{frame}
\titlepage
\end{frame}

\begin{frame}
\tableofcontents
\end{frame}

\iffrench{
\section{Bon}
\subsection{jour}
}{
\section{Hellow}
\subsection{world}
}

\begin{french}
{French frame}
\blindtext
\end{french}


\begin{english}
{English frame}
\blindtext
\end{english}


\begin{french}
{French frame}
\blindtext
\end{french}

\begin{english}
{English frame}
\blindtext
\end{english}

\end{document}
touhami
  • 19,520
  • Thanks, but I see two problems with your solution: first, it does not set the default language (for example, your blind text is always the French one, even if french is not set to true) and it also does not handle well sections with the theme I use, JuanLesPins: I have to declare new sections inside the French/English frames and their names only appear at the slide after which they were declared. – Anab Jun 26 '15 at 11:55
  • @Anab answer edited. – touhami Jun 27 '15 at 12:31
  • @Anab another solution that use comment package – touhami Jun 27 '15 at 23:41
  • I really like both of your solutions. However, I ran in a small issue with the first one: it seems not to handle accentuation. I have some occurrences of "é" in my French slides and the first one returns Package inputenc Error: Unicode char \u8:éme not set up for use with LaTeX. I use \usepackage[utf8]{inputenc} in my preamble to handle compatibility between the Mac and Windows I use and my documents are encoded in utf-8. – Anab Jun 29 '15 at 15:26
  • Of course you need to load all packages necessary, as normal way. – touhami Jun 29 '15 at 15:55
  • Well, my problem is that I do load inputenc with the correct encoding and that does not seem to work. I suspect that maybe, the fact that the comment create an auxiliary file for each included comment mess with the encoding (but I have no idea how or why) because the "é" becomes an "È" in the auxiliary file. – Anab Jun 29 '15 at 20:38
  • see egreg answer to this http://tex.stackexchange.com/questions/159820/comment-sty-and-utf8-encoding – touhami Jun 29 '15 at 21:15
  • @Anab did you see my last comment – touhami Jun 30 '15 at 16:30
  • Yes, sorry, I had a busy day and did not have the chance to try out egreg answer but since the question is similar to my problem, I have no doubt its answer will work for me. Thanks again for looking at my question. :) – Anab Jun 30 '15 at 18:00