I am writing a document in English, and no words are being hyphenated unless I include them in a `\hyphenation{*}` command. For instance, the word 'government' protrudes into the margin unless I include `\hyphenation{gov-ern-ment}` in the preamble.

I don't think this can be an issue with `\hyphenpenalty` or `\lefthyphenmin` and `\righthyphenmin`, since once words are included in the `\hyphenation{*}` command everything works fine (and because I've tried fiddling with these parameters and it's not fixed anything). I've also tried putting `\usepackage[english]{babel}` in the preamble and that's not fixed anything. I've just reinstalled MiKTeX and updated all my packages, so I don't think that can be an issue.

EDIT 4:
This seems to be problem with TeXStudio, as my minimal example works fine in the command line, using `pdflatex hyphenation-example`.

EDIT:
I'm using document class `book`, with subfiles, though I've had a similar problem with the document class `article` in the past.

Here's my full preamble. I had this issue before I defined any custom commands, so the packages section is likely the most relevant.

```
% LATEX PARAMETERS_________________________________________________________________________
%default values are 50
\hyphenpenalty = 50 % lower means more hyphenation
\tolerance = 50 % lower means less stretching between words, more likelihood of jagged edge, and more hyphenation
\lefthyphenmin = 2
\righthyphenmin = 2

% PACKAGES_________________________________________________________________________________

% general functionality
\usepackage{amsmath} % matrices
\usepackage{amssymb} % fancy maths letters
\usepackage{breqn} % equations over several lines
\usepackage{graphicx} % import figures
\usepackage{caption} % caption figures
\usepackage{subcaption} % subfigures
\captionsetup{font={small},labelfont={bf},labelsep=space}
\usepackage{xparse} % needed for shortenthis command and commands with an if-then structure
\usepackage[pagestyles,explicit,raggedright]{titlesec} % change title style
\usepackage{needspace} % insert pagebreak if not enough space
\usepackage[nottoc,notlot,notlof]{tocbibind} % inlcude bibliography in toc
\usepackage{subfiles}

% fonts
\usepackage[bitstream-charter]{mathdesign} % set font to BT Charter
\usepackage[T1]{fontenc} % font encoding
\newcommand{\sansfont}{\fontfamily{qag}\selectfont} % command to set font to TeX Gyre Heros

% ornaments
\usepackage{adforn} % fleurons
\newcommand{\ico}{\includegraphics[height=0.8 em]{Icosahedron}}
\newcommand{\flower}{\begin{center}\Large\adfflowerright\end{center}}

% draft formatting
\usepackage{setspace} % line spacing
\usepackage{lineno} % line numbering

% page formatting
\usepackage[left = 35mm, right = 25mm, top = 30mm, bottom = 30 mm, headsep = 12mm, footskip = 15mm]{geometry} % page margins

% making diagrams
\usepackage{tikz} % make diagrams in LaTeX
\usetikzlibrary{arrows.meta} % set arrow appearance
\tikzset{>={Latex[width=3mm,length=3mm]}}
\pgfdeclarelayer{bg} % for loops
\pgfsetlayers{bg,main}

% references
\usepackage{hyperref}
\newcommand{\doi}[1]{\textsc{doi}: \href{http://dx.doi.org/#1}{\nolinkurl{#1}}} % allows underscores in dois

% colors
\usepackage{color}
\definecolor{vp}{HTML}{440154} % viridis purple
\definecolor{vb}{HTML}{33638D} % viridis blue
\definecolor{vg}{HTML}{3CBB75} % viridis green
\definecolor{vy}{HTML}{FDE725} % viridis yellow
\definecolor{IBMb}{HTML}{648FFF} % IBM blue
\definecolor{IBMr}{HTML}{DC267F} % IBM red
\definecolor{IBMy}{HTML}{FFB000} % IBM yellow
\definecolor{IBMp}{HTML}{785EF0} % IBM purple

% COMMANDS_________________________________________________________________________________

% define the 'shortenthis' command, which I use in the definition abbreviations. sourced from Manuel on StackExchange, in an answer posted on 2014-03-01
\ExplSyntaxOn
\NewDocumentCommand\shortenthis{ m }
    {\shorten_this:n { #1 }}
\seq_new:N \l_shorten_seq
\cs_new_protected:Npn \shorten_this:n #1
    {\seq_set_split:Nnn \l_shorten_seq { ~ } { #1 }
    \seq_map_inline:Nn \l_shorten_seq
    {\tl_head:n { ##1 } }}
\ExplSyntaxOff

% define documentstyle option 'draft'. in draft documents certain commands will behave differently
\newif\if@myfilerough
\DeclareOption{rough}{\@myfileroughtrue}

\ProcessOptions\relax

\if@myfilerough
  % in a rough rough text shows up and is noted in the margin
  \newcommand{\rough}[1]{$<$#1$>$\marginpar{\color{magenta}\textbf{rough}}}
  \newcommand{\citerough}[1]{[[#1]]\marginpar{\color{blue}\textbf{cite}}}
  % in a rough definitions are noted in the margin, with an optional argument for an abbreviation
  \NewDocumentCommand{\term}{o m}{%
    \IfNoValueTF{#1}%
      {\emph{#2}\marginpar{\textbf{``\shortenthis{#2}''}}}%
      {\emph{#2} (#1)\marginpar{\textbf{``#1''}}}%
  }
  % roughs have 1.5x spacing and line numbers
  \onehalfspacing
  \linenumbers
\else
  % in a non-rough rough text is not shown
  \newcommand{\rough}[1]{}
  \newcommand{\citerough}[1]{}
  % in a non-rough definitions are emphasised but are not noted in the margin
  \NewDocumentCommand{\term}{o m}{%
    {\emph{#2}}%
  }
\fi

%for use at end of chapters to make the next page occur on the left
\newcommand*\cleartoleftpage{%
  \clearpage
  \ifodd\value{page}\hbox{}\newpage\fi
}

% FORMATTING________________________________________________________________________________

\titleformat{\chapter}[hang]{\raggedright\sansfont\singlespacing\Huge}{\thechapter\hspace{20pt}\ico\hspace{20pt}}{0pt}{\Huge #1}[]%

\titleformat{\section}[hang]{\needspace{0.5in}\sansfont\singlespacing}{}{0pt}{\LARGE #1 \Large \hfill \ico~\thesection}[]%

\titleformat{\subsection}[hang]{\needspace{0.5in}\sansfont\singlespacing}{}{0pt}{\Large #1 \large \hfill \ico~\thesubsection}[]%

\titleformat{\subsubsection}[hang]{\needspace{0.5in}\sansfont\singlespacing\normalsize}{}{0pt}{\large #1 \hfill}[]%

% Redefine headers
\newpagestyle{main}{% 
  \sethead[\sansfont \thepage \hspace{.7cm} \textsl{\chaptertitle}][][]
  {}{}{\sansfont \textsl{\thesection~\ {\ico} \ \sectiontitle} \hspace{.7cm} \thepage}
  \setfoot{}{}{}
} % Define page style main
\pagestyle{main} % Use page style main

\renewpagestyle{plain}{% 
  \setfoot{}{}{}
} % Define page style plain (first pages of chapters etc)

\title{thesis}
\author{ben}

\endinput

```

EDIT 2:

Here's a minimal example, with the textwidth set very low to show that hyphenation isn't working:

```
\documentclass[draft]{book}
\textwidth=4cm
\usepackage[english,showlanguages]{babel}

\begin{document}
A pandemic is an event in which a disease spreads over a very large area, often crossing national borders. Pandemics often infect large numbers of people, can cause many deaths , and have negative effects on trade and the world economy. It is due to the large scale of the negative effects of pandemics that pandemic preparedness is seen as an important public health activity, despite the low frequency of pandemics in comparison to other disease outbreaks. Factors implicated in pandemic risk include travel, high population density, and changing agricultural practices.
\end{document}

```

[![LaTeX PDF output showing failure of hyphenation](https://i.stack.imgur.com/GWPNZ.png)](https://i.stack.imgur.com/GWPNZ.png)

And here's the log file:

```
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (MiKTeX 21.6) (preloaded format=pdflatex 2021.7.15)  15 JUL 2021 16:17
entering extended mode
**./hyphenation-example.tex
(hyphenation-example.tex
LaTeX2e <2021-06-01> patch level 1
L3 programming layer <2021-07-12>
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/latex/base/b
ook.cls
Document Class: book 2021/02/12 v1.4n Standard LaTeX document class

(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/latex/base/b
k10.clo
File: bk10.clo 2021/02/12 v1.4n Standard LaTeX file (size option)
)
\c@part=\count182
\c@chapter=\count183
\c@section=\count184
\c@subsection=\count185
\c@subsubsection=\count186
\c@paragraph=\count187
\c@subparagraph=\count188
\c@figure=\count189
\c@table=\count190
\abovecaptionskip=\skip47
\belowcaptionskip=\skip48
\bibindent=\dimen138
)
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/generic/babe
l/babel.sty
Package: babel 2021/06/28 3.61 The Babel package
<*languages>
</languages>

(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/generic/babe
l/babel.def
File: babel.def 2021/06/28 3.61 Babel common definitions
\babel@savecnt=\count191
\U@D=\dimen139
\l@unhyphenated=\language1

(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/generic/babe
l/txtbabel.def)
\bbl@readstream=\read2
)
\bbl@dirlevel=\count192

*************************************
* Local config file bblopts.cfg used
*

(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/latex/arabi/
bblopts.cfg
File: bblopts.cfg 2005/09/08 v0.1 add Arabic and Farsi to "declared" options of
 babel
)
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/latex/babel-
english/english.ldf
Language: english 2017/06/06 v3.3r English support from the babel system
))
(/Users/user/Library/Application Support/MiKTeX/texmfs/install/tex/latex/l3back
end/l3backend-pdftex.def
File: l3backend-pdftex.def 2021-07-12 L3 backend support: PDF output (pdfTeX)
\l__color_backend_stack_int=\count193
\l__pdf_internal_box=\box50
) (hyphenation-example.aux)
\openout1 = `hyphenation-example.aux'.

LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.
LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 5.
LaTeX Font Info:    ... okay on input line 5.

Overfull \hbox (3.46695pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 over a very large area, often|
 []

Overfull \hbox (6.6892pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 Pandemics often infect large|
 []

Overfull \hbox (9.60585pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 numbers of people, can cause|
 []

Overfull \hbox (24.52258pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 many deaths , and have negative|
 []

Overfull \hbox (11.85583pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 effects on trade and the world|
 []

Overfull \hbox (3.55031pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 seen as an important public|
 []

Overfull \hbox (3.21696pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 low frequency of pandemics|
 []

Overfull \hbox (14.74475pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 in comparison to other disease|
 []

Overfull \hbox (15.2911pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 outbreaks. Factors implicated|
 []

Overfull \hbox (19.63367pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 in pandemic risk include travel,|
 []

Overfull \hbox (8.13373pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 high population density, and|
 []

Overfull \hbox (21.05035pt too wide) in paragraph at lines 6--7
\OT1/cmr/m/n/10 changing agricultural practices. |
 []

[1{/Users/user/Library/Application Support/MiKTeX/texmfs/data/pdftex/config/pdf
tex.map}

] (hyphenation-example.aux) ) 
Here is how much of TeX's memory you used:
 1207 strings out of 480807
 19477 string characters out of 2898544
 325395 words of memory out of 3000000
 18943 multiletter control sequences out of 15000+600000
 403783 words of font info for 28 fonts, out of 8000000 for 9000
 0 hyphenation exceptions out of 8191
 40i,5n,52p,619b,149s stack positions out of 5000i,500n,10000p,200000b,80000s
</Users/user/Library/Application Support/MiKTeX/te
xmfs/install/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on hyphenation-example.pdf (1 page, 18944 bytes).
PDF statistics:
 11 PDF objects out of 1000 (max. 8388607)
 0 named destinations out of 1000 (max. 500000)
 1 words of extra memory for PDF output out of 10000 (max. 10000000)

```

Adding a `\hyphenation{*}` command means that hyphenation can occur.

```
\documentclass{book}
\textwidth=4cm
\usepackage[english,showlanguages]{babel}
\hyphenation{of-ten}

\begin{document}
A pandemic is an event in which a disease spreads over a very large area, often crossing national borders. Pandemics often infect large numbers of people, can cause many deaths , and have negative effects on trade and the world economy. It is due to the large scale of the negative effects of pandemics that pandemic preparedness is seen as an important public health activity, despite the low frequency of pandemics in comparison to other disease outbreaks. Factors implicated in pandemic risk include travel, high population density, and changing agricultural practices.
\end{document}

```

[![LaTeX PDF output showing the word 'often' hyphenated](https://i.stack.imgur.com/Gp8MO.png)](https://i.stack.imgur.com/Gp8MO.png)

Edit 3:
Screenshot of commands in TeXStudio[![screenshot of commands in TeXstudio, in particular the pdflatex command being pdflatex -synctex=1 -interaction=nonstopmode %.tex](https://i.stack.imgur.com/Yh7Cq.png)](https://i.stack.imgur.com/Yh7Cq.png)