Change font in section headings only

fontssectioning

I'm writing a handbook for an organisation who has specific fonts (Montserrat for Titles and headings; Source Sans Pro for the text).
I can change the font to either of them using
https://tug.org/FontCatalogue/montserratregular/ and
https://tug.org/FontCatalogue/sourcesanspro/, respectively.

But I don't know how to get it into \allsectionsfont
Or into \fontfamily because the examples I found are for the "standard" fonts.

\documentclass[a4paper,12p]{book}

\usepackage[T1]{fontenc}
\usepackage[default]{sourcesanspro}
%\usepackage[defaultfam,tabular,lining]{montserrat} %% Option 'defaultfam'
%%% only if the base font of the document is to be sans serif
%\usepackage[T1]{fontenc}
\renewcommand*\oldstylenums[1]{{\fontfamily{Montserrat-TOsF}\selectfont #1}}

\usepackage{sectsty}
    \allsectionsfont{\sffamily}

\begin{document}
\setlength{\parindent}{0pt} % never indent first line

\chapter{Introduction}

\section{Why join?}

This document is a sample document to 
test font families and font typefaces.\\
{\fontfamily{cmss}\selectfont
This text uses a different font typeface
}

\end{document}

How do I need to change my code?

Best Answer

The two packages fight each other in how to define \sfdefault.

I suggest to first load sourcesanspro and make it \rmdefault. Then you can load montserrat.

\documentclass[a4paper,12pt]{book}

\usepackage[T1]{fontenc}
\usepackage{sectsty}

\usepackage{sourcesanspro}

% set the default font to SourceSansPro
\RenewCommandCopy{\rmdefault}{\sfdefault}

\usepackage[tabular,lining]{montserrat}

\allsectionsfont{\sffamily}

\setlength{\parindent}{0pt} % never indent first line

\begin{document}

\chapter{Introduction}

\section{Why join? \fontname\font}

This document is a sample document to 
test font families and font typefaces.
\fontname\font

\end{document}

The \fontname\font instructions show what font is being used.

enter image description here

Without the default or defaultfam options, the two packages just set \sfdefault. After loading sourcesanspro, we change \rmdefault to what sourcesanspro thinks is \sfdefault. After that we can load montserrat that sets \sfdefault.