# figure environment isn't compiling with babel and hebrew in pdflatex

I have a project that is written both in Hebrew and in English, which is compiled with pdfLatex on Overleaf. Since this compiler is not a Unicode engine, one has to declare the Hebrew letters explicitly (as I learned here). This is the reason for the \DeclareUnicodeCharacter{---}{\heb---} commands in the preamble below.

It works fine, up until the moment I wanted to insert an image to my document, with a figure environment.

The main.tex and chapter01.tex files are given below, with the hierarchical file structure:

\documentclass{tufte-book} % Tufte-book format
% Encoding stuff
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[main=english, hebrew]{babel}

%% Herbew letters declarations %%
\DeclareUnicodeCharacter{05D0}{\hebalef}
\DeclareUnicodeCharacter{05D1}{\hebbet}
% and so on until
\DeclareUnicodeCharacter{05EA}{\hebtav}

\usepackage{subfiles} % Best loaded last in the preamble. Used to break the content of the project into smaller files

\begin{document}
\subfile{subfiles/chapter01}
\subfile{subfiles/chapter02}
\end{document}

\documentclass[main.tex]{subfiles}

\begin{document}
\selectlanguage{hebrew}
כיתוב בעברית.
\selectlanguage{english}
Some english text, and this is a figure:
\begin{figure}
\centering
\includegraphics{images/figure01.png}
\end{figure}
% No figure!
\end{document}

root folder
├main.tex
└───figures
| │ figure01.png
│ │ figure02.png
│ │ figure03.png
└───subfiles
| │ chapter01.tex
| │ chapter02.tex
| │ chapter03.tex


The log has the following errors:

Missing \endcsname inserted.
Use of \m@^_ doesn't match its definition.
Missing number, treated as zero.
Extra \endcsname.
Undefined control sequence.   l.10  \includegraphics{figures/figure.png}


Can anyone address me to why it happens and how to fix it?

Output:

• If this is too much trouble to make latex work with hebrew alphabet and if as you suggested (tex.stackexchange.com/questions/586500/…) you only need it for the first page, I would suggest to create the first page separately and use pdfpages to include it in your document. Mar 16 at 21:13
• I wasn't aware of this package. Seems correct to me.
– tush
Mar 16 at 21:22

This seems to be a clash between the changepage package (which is used by tufte-book) and the babel support for Hebrew, which changes to code for arabic numbers.

It will probably be solved by putting these lines in your preamble:

\makeatletter
\def\thecp@cntr{\@@arabic\c@cp@cntr}
\makeatother


And the undefined control sequence can be solved by adding

\usepackage{graphicx}

• Your suggestion helps to some extent. It solves the first four errors I noted in the original post, but Undefined control sequence. l.10 \includegraphics{figures/figure.png} is still there.
– tush
Mar 16 at 20:40
• Actually, when I change the document class from tufte-book to article, for example, there seems to be no need for the \def\thecp@cntr{\@@arabic\c@cp@cntr} command you mentioned, but the "Undefined control sequence" error persists.
– tush
Mar 16 at 21:00
• That is right, because it is caused by the changepage package and that is not used with the article class. And the undefined control sequence is probably because you forgot \usepackage{graphicx} Mar 17 at 8:28