2

I use the "report" document class for a document written in swedish (that's got åäöÅÄÖ). I also use the babel-package for swedish. It works as supposed, but now LaTeX has troubles hyphenating some of my special words, so I had to add this:

\hyphenation{
  nät-spänn-ing
  nät-spänn-ing-ar
  lik-spänn-ing
  spänn-ing
  spänn-ing-en
  belys-nings-lamp-orna
}

However, to hyphenate swedish words I also need to add:

\usepackage[T1]{fontenc}

otherwise I got some fatal errors, and google told me to use the above line.

But, when using T1, all åäöÅÄÖ are stripped away from every chapter name in the whole document. The document itself still has åäöÅÄÖ, but chapter names are gone.

Question: How do I add special hyphenation rules for swedish words without breaking the section names containing swedish characters?

(see updated question at the bottom)

EDIT

My question was incomplete as it lacks proper examples. Here's a screenshot of the error in question:

enter image description here

This is the source:

% -*- latex -*-
\documentclass[12pt,a4paper,twoside]{report}
\newif\iflargephoto

\largephototrue

\usepackage{xjobb}

\usepackage[T1]{fontenc}

\hyphenation{
  nät-spänn-ing
  nät-spänn-ing-ar
  lik-spänn-ing
  spänn-ing
  spänn-ing-en
  belys-nings-lamp-orna
}


\usepackage[swedish]{babel}   % date format and hyphenation rules(?)
\selectlanguage{swedish}
\usepackage[utf8]{inputenc}


\begin{document}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagenumbering{arabic}
\chapter{Swedish chars: å and ä and ö}
Swedish chars: å and ä and ö

\end{document}

If I remove the line \usepackage[T1]{fontenc} then the swedish characters can be seen in the chapter heading, but then the \hyphenation{} breaks completely:

! Improper \hyphenation will be flushed.
\leavevmode ->\unhbox 
                      \voidb@x 
l.12   nä
          t-spänn-ing
! Not a letter.
\leavevmode ->\unhbox \voidb@x 

l.12   nä
          t-spänn-ing
! Improper \hyphenation will be flushed.

[...lots of repeated errors cut away...]

The fancy chapter names are obviously generated by the package xjobb (swedish slang for "ex-jobb", which is "thesis"). Removing this and åäöÅÄÖ can be seen in the chapter names, but the look is awfully boring so I really do not want to remove it.

I have not written, nor touched, the xjobb-package. A lot of other people at my university has used it for their thesis, but the difference here is that they wrote it in English and never had my problem, and that's probably why no-one has noticed the errors.

The xjobb-package is quite small so I add it here:

% START xjobb-package
%
%  Package file with options making me feel better...
%  (Author: Stefan Langemark)
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{xjobb}[1999/04/16 Class setup for xjobb]

\RequirePackage{parskip}
\RequirePackage{geometry}
\RequirePackage[utf8]{inputenc}
\RequirePackage{fancyhdr}

%
%--------------------------------
%    Paper layout
%    (no room for margin notes)
%--------------------------------
%
% paper=b5paper,
\geometry{
  paperwidth = 165mm, paperheight = 240mm,
%   paper = a4paper,
   total = {130mm,220mm},
%  marginparsep = 2mm,
%  marginparwidth = 15mm,
  includemp = false,
  %twosideshift = 10pt
}
\addtolength{\headheight}{3pt}

%-------------------------------
%    Header/Footer
%-------------------------------

\renewcommand{\headrulewidth}{0.4pt}
\fancyhf{}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\fancyhead[RO,LE]{\bfseries\thepage}
\pagestyle{fancy}
%\pagestyle{plain}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0pt}
}

%
%-------------------------------
%  Redefining section styles
%  to suit parskip > 0
%-------------------------------
%
%\addtocounter{secnumdepth}{1}% Number subsubsections too
%\addtocounter{tocdepth}{1}%    Include subsections in table of contents.

\renewcommand\section{\@startsection%
  {section}%
  {1}%
  {\z@}%
  {-2.5ex \@plus -1ex \@minus -.2ex}%
  {1.3ex \@plus.2ex}%
  {\normalfont\Large\bfseries}%
}
\renewcommand\subsection{\@startsection%
  {subsection}%
  {2}%
  {\z@}%
  {-2.25ex\@plus -1ex \@minus -.2ex}%
  {0.5ex \@plus .2ex}%
  {\normalfont\large\bfseries}%
}
\renewcommand\subsubsection{\@startsection%
  {subsubsection}%
  {3}%
  {\z@}%
  {-2.25ex\@plus -1ex \@minus -.2ex}%
  {0.1pt \@plus .2ex}%
  {\normalfont\mdseries\large\itshape}%
}
%
%-------------------------------------
%  Redefine {chapter,section}mark to 
%  remove ugly all-uppercase
%-------------------------------------
%
\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter.\enspace #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\enspace #1}}
%
%
\renewcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname}%
    \markboth{\contentsname}{\contentsname}%
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }
\renewcommand\listoffigures{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\listfigurename}%
    \markboth{\listfigurename}{\listfigurename}%
    \@starttoc{lof}%
    \if@restonecol\twocolumn\fi
    }
\renewcommand\listoftables{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\listtablename}%
    \markboth{\listtablename}{\listtablename}%
    \@starttoc{lot}%
    \if@restonecol\twocolumn\fi
    }
%
%-------------------------------------------
%  Chapter (stolen from Kluwer book style)
%-------------------------------------------
%
\font\chapnumber=cmbx10 at 50pt                  %% chapter number
%\font\chaptitle=cmbx10 scaled\magstep3           %% chapter title
\font\chaptitle=cmbx10 at 20pt           %% chapter title

\def\bigraggedleft{\leftskip0pt plus1fil\relax}

\def\@makechapterhead#1{%\null\vskip-5pc
\vbox to 14pc{\hbox to\textwidth{\hfill\chapnumber\thechapter}
\hyphenpenalty=10000 % No hyphenation in chapter heads
\vskip8pt
\hrule height 1.5pt
\vskip12pt\vskip-\parskip
\def\\ {\vskip-\parskip}\parfillskip=0pt
\bigraggedleft
\LARGE\chaptitle{\def\\ {\vskip-\parskip}#1}\vskip1sp
\vfill}}

\def\@makeschapterhead#1{\vbox to 7.5pc{
\hrule height 1.5pt
\hyphenpenalty=10000 % No hyphenation in chapter heads
\vskip12pt\vskip-\parskip
\def\\ {\vskip-\parskip}\parfillskip=0pt
\LARGE\bigraggedleft
\chaptitle{#1}\vskip1sp\vfill}}
% END xjobb-package

Hopefully I have now gathered all the required information for this question, and I really hope I still can use the xjobb-package because I really like the look of it.

So, question: Is it the xjobb-package that breaks åäöÅÄÖ in the chapter names? If so, how can I rewrite it so it works?

  • 4
    Welcome to TeX.SE. It would be helpful if you composed a fully compilable minimal working example (MWE) including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – user36296 Nov 14 '18 at 22:45
  • 1
    Please also tell us which TeX distribution you employ, and how old it is. I take it you use pdfLaTeX. Please advise if this assumption is incorrect. – Mico Nov 15 '18 at 7:29
  • 2
    For what it's worth, I am unable to generate any errors if I expand your code snippet to make it compilable, while making sure to load the inputenc package with the option utf8. Incidentally, if babel is loaded with the option swedish, the only word that needs help in terms of finding valid hyphenation points is belysningslamporna; the other five words get hyphenated correctly without further help if babel is loaded with the option swedish. – Mico Nov 15 '18 at 7:36
  • 1
    @mico: I will edit my post when I get back from work and add a minimal example that shows the error. I'm using LaTeX that comes with Debian Stretch. Thanks for pointing out. – bos Nov 15 '18 at 8:30
  • @samcarter Thanks for the input. I have now rewritten my question completely, and provided code. – bos Nov 16 '18 at 18:46
2

Listen, I’ve simply tried to fix your problem, but I’m afraid the package should undergo an extensive review. Try saving the following code in the same directory as the (main) file you want to compile, under the name newxbjobb.sty:

%  Package file with options making me feel better...
%  (Author: Stefan Langemark)
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{newxjobb}[2018/11/16 *** To be reviewed! ***]

\RequirePackage{parskip}
\RequirePackage{geometry}
\RequirePackage[T1]{fontenc} % ... the following line doesn't make much sense 
                             % without this one
\RequirePackage[utf8]{inputenc}
\RequirePackage{fancyhdr}

%
%--------------------------------
%    Paper layout
%    (no room for margin notes)
%--------------------------------
%
% paper=b5paper,
\geometry{ 
  paperwidth = 165mm, paperheight = 240mm,
%   paper = a4paper,
   total = {130mm,220mm},
%  marginparsep = 2mm,
%  marginparwidth = 15mm,
  includemp = false,
  %twosideshift = 10pt
}
\addtolength{\headheight}{3pt} % ??? (use "\geometry{...}" instead!)

%-------------------------------
%    Header/Footer
%-------------------------------

\renewcommand{\headrulewidth}{0.4pt}
\fancyhf{}
\fancyhead[LO]{\bfseries\rightmark}
\fancyhead[RE]{\bfseries\leftmark}
\fancyhead[RO,LE]{\bfseries\thepage}
\pagestyle{fancy}
%\pagestyle{plain}
\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0pt}
}

%
%-------------------------------
%  Redefining section styles
%  to suit parskip > 0
%-------------------------------
%
%\addtocounter{secnumdepth}{1}% Number subsubsections too
%\addtocounter{tocdepth}{1}%    Include subsections in table of contents.

\renewcommand\section{\@startsection%
  {section}%
  {1}%
  {\z@}%
  {-2.5ex \@plus -1ex \@minus -.2ex}%
  {1.3ex \@plus.2ex}%
  {\normalfont\Large\bfseries}%
}
\renewcommand\subsection{\@startsection%
  {subsection}%
  {2}%
  {\z@}%
  {-2.25ex\@plus -1ex \@minus -.2ex}%
  {0.5ex \@plus .2ex}%
  {\normalfont\large\bfseries}%
}
\renewcommand\subsubsection{\@startsection%
  {subsubsection}%
  {3}%
  {\z@}%
  {-2.25ex\@plus -1ex \@minus -.2ex}%
  {0.1pt \@plus .2ex}%
  {\normalfont\mdseries\large\itshape}%
}
%
%-------------------------------------
%  Redefine {chapter,section}mark to 
%  remove ugly all-uppercase
%-------------------------------------
%
\renewcommand{\chaptermark}[1]{\markboth{\chaptername\ \thechapter.\enspace #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection\enspace #1}}
%
%
\renewcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname}%
    \markboth{\contentsname}{\contentsname}%
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }
\renewcommand\listoffigures{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\listfigurename}%
    \markboth{\listfigurename}{\listfigurename}%
    \@starttoc{lof}%
    \if@restonecol\twocolumn\fi
    }
\renewcommand\listoftables{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\listtablename}%
    \markboth{\listtablename}{\listtablename}%
    \@starttoc{lot}%
    \if@restonecol\twocolumn\fi
    }
%
%-------------------------------------------
%  Chapter (stolen from Kluwer book style)
%-------------------------------------------
%
\newcommand*\chapnumber{% chapter number
    \fontsize{50}{60}%
    \usefont{T1}{lmr}{bx}{n}%
}
\newcommand*\chaptitle{% chapter title
    \fontsize{20}{24}%
    \usefont{T1}{lmr}{bx}{n}%
}

\def\bigraggedleft{\leftskip0pt plus1fil\relax}

\def\@makechapterhead#1{%\null\vskip-5pc
\vbox to 14pc{\hbox to\textwidth{\hfill\chapnumber\thechapter}
\hyphenpenalty=10000 % No hyphenation in chapter heads
\vskip8pt
\hrule height 1.5pt
\vskip12pt\vskip-\parskip
\def\\ {\vskip-\parskip}\parfillskip=0pt
\bigraggedleft
\chaptitle{\def\\ {\vskip-\parskip}#1}\vskip1sp
\vfill}}

\def\@makeschapterhead#1{\vbox to 7.5pc{
\hrule height 1.5pt
\hyphenpenalty=10000 % No hyphenation in chapter heads
\vskip12pt\vskip-\parskip
\def\\ {\vskip-\parskip}\parfillskip=0pt
\bigraggedleft
\chaptitle{#1}\vskip1sp\vfill}}
% END xjobb-package

Then, in your main file, replace

\usepackage{xjobb}

with

\usepackage{newxjobb}

Also, remove the two lines

\usepackage[T1]{fontenc}

and

\usepackage[utf8]{inputenc}

from your main file: they are not/no longer necessary.

  • Magic! Works like a charm. Now I just have to peek a diff of the files to see and learn what was wrong. – bos Nov 17 '18 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.