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:

pdfpagesto include it in your document. – nlair Mar 16 '21 at 21:13