\newgeometry doesn't work with Turkish babel package
A solution for \includegraphics
as you've requested in the above comments.
Add the following lines in the preamble:
\usepackage{etoolbox}
\let\oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{%
\oldincludegraphics[#1]{#2}%
\shorthandon{=}%
}
\pretocmd{\includegraphics}{\shorthandoff{=}}{}{}
We first redefine \includegraphics
to add \shorthandon{=}
after it and then, through the \pretocmd
command from the etoolbox
package, we prefix \includegraphics
with \shorthandoff{=}
.
Complete MWE
\documentclass[]{article}
\usepackage[turkish]{babel}
\usepackage{graphicx}
\usepackage{etoolbox}
\let\oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{%
\oldincludegraphics[#1]{#2}%
\shorthandon{=}%
}
\pretocmd{\includegraphics}{\shorthandoff{=}}{}{}
\begin{document}
\includegraphics[width=4cm]{example-image-a}
\end{document}
Output:
\usepackage[turkish]{babel}
makes =
active. That disturbs key value parser, because they usually assume that the syntax characters =
and ,
have the usual catcode (other=12). The official way is indeed using
\shorthandoff{=}
% stuff that does not expect an active `=', e.g.
\newgeometry{top=1cm}
\shorthandon{=}
Package keyval
: \kvsetkeys
A more comfortable way is provided by package kvsetkeys
. Its key value parser was written with turkish.ldf
in mind. Thus it supports active syntax characters in key value lists. The package defines \kvsetkeys
, which can now be
used as direct replacement for \setkeys
of package keyval
:
\usepackage{keyval,kvsetkeys}
\let\setkeys\kvsetkeys
Package xkeyval
The package directly redefines and extends \setkeys
:
\usepackage{xkeyval}
hen active equal signs are supported in key value lists that are processed by \setkeys
.
Compatibility
Package xkeyval
also changes more things, like the parsing of package and class options, even for packages that do not use or know xkeyval
.
Therefore I consider the solution with kvsetkeys
less intrusive.
However, both solutions can easily cooperate, even if xkeyval
might be loaded by the class or other packages.
The trick is using the first method as early as possible:
\RequirePackage{keyval,kvsetkeys}
\let\setkeys\kvsetkeys
% classes and packages that might load xkeyval
\documentclass{...}
% packages in any order, e.g.
\usepackage{geometry}
\usepackage[turkish]{babel}
\usepackage{graphicx}
\begin{document}
% then the following works without `\shorthandoff{=}`:
\newgeometry{top=1cm}
\includegraphics[width=\linewidth]{...}
Then active equal signs are supported by package kvsetkeys
as default or by xkeyval
for the case that it is loaded later.
With babel
3.9 (if you are not using it, upgrade, because it fixes tons of bugs):
\usepackage[turkish,shorthands=off]{babel}
or if you want :
and !
:
\usepackage[turkish,shorthands=:!]{babel}
The Turkish style has been upgrade recently, too. The new manual explains how to deal with the =
.