Aarhus University (AU) LaTeX Character Count Guide

This guide walks you through setting up an automated system to calculate "Standard Pages" (2,400 characters including spaces) in LaTeX, natively handling both Windows and Linux environments, and embedding the result directly into your document.

0. Dependencies

Before you can use the scripts, ensure you have the following installed:

1. The Counting Scripts

Create these two script files in the same directory as your main.tex file. They will use TeXcount to calculate the words and characters, estimate the spaces, and output the final page count to a text file.

Linux / Mac Script (au_count.sh)

Save this as au_count.sh and run chmod +x au_count.sh in your terminal to make it executable.

#!/bin/bash

MAIN_FILE="1main.tex"

echo "Calculating..."

# Run the commands and store the output in variables
WORDS=$(texcount -inc -1 -sum=1,1,0,1,1,1,1 "$MAIN_FILE")
CHARS=$(texcount -char -inc -1 -sum=1,1,0,1,1,1,1 "$MAIN_FILE")

# Add words and characters together to simulate spaces
TOTAL_WITH_SPACES=$((WORDS + CHARS))

# Calculate Aarhus University standard pages (2400 chars/page)
PAGES=$(echo "scale=2; $TOTAL_WITH_SPACES / 2400" | bc)

# Print the results to the terminal
echo "-----------------------------------"
echo "Words:                   $WORDS"
echo "Characters (no spaces):  $CHARS"
echo "Total (with spaces):     $TOTAL_WITH_SPACES"
echo "AU Standard Pages:       $PAGES"
echo "-----------------------------------"

# Save just the page count to a text file for LaTeX to read
echo $PAGES > au_result.txt

Windows Script (au_count.bat)

Save this as au_count.bat.

@echo off
set MAIN_FILE=1main.tex

echo Calculating...

:: Run TeXcount and save output to temporary files
texcount -inc -1 -sum=1,1,0,1,1,1,1 %MAIN_FILE% > temp_words.txt
set /p WORDS=<temp_words.txt

texcount -char -inc -1 -sum=1,1,0,1,1,1,1 %MAIN_FILE% > temp_chars.txt
set /p CHARS=<temp_chars.txt

:: Delete the temporary files
del temp_words.txt
del temp_chars.txt

:: Add words and characters together
set /a TOTAL_WITH_SPACES=%WORDS%+%CHARS%

:: Calculate standard pages using built-in PowerShell for decimals
for /f %%i in ('powershell -command "{0:N2}" -f (%TOTAL_WITH_SPACES% / 2400)') do set PAGES=%%i

:: Print the results to the terminal
echo -----------------------------------
echo Words:                   %WORDS%
echo Characters (no spaces):  %CHARS%
echo Total (with spaces):     %TOTAL_WITH_SPACES%
echo AU Standard Pages:       %PAGES%
echo -----------------------------------

:: Save just the page count to a text file for LaTeX to read
echo %PAGES% > au_result.txt

2. Automating in LaTeX

To have LaTeX automatically detect your OS, run the correct script, and print the result, add the following to your 1main.tex.

The Preamble

\usepackage{ifplatform}

% Run the correct script based on the operating system
\ifwindows
    \immediate\write18{au_count.bat}
\else
    \immediate\write18{./au_count.sh}
\fi

Displaying the Result

Place this where you want the final number to appear (e.g., your title page):

\textbf{Total Standard Pages (including spaces):} \input{au_result.txt}
CRITICAL: Enable Shell Escape
For \write18 to work, you must compile your document with the shell escape flag enabled. If using the terminal, compile with:
pdflatex -shell-escape 1main.tex
If using an editor like TeXstudio or VS Code, add --shell-escape to your compiler arguments in the settings.

3. Ignoring Specific Sections

Front pages, table of contents, bibliographies, and certain appendices should not count towards your limit. You can exclude specific blocks of text directly in your LaTeX code using TeXcount comments.

%TC:ignore
\section*{Preface}
This text, and anything inside this block, will be completely 
ignored by TeXcount and will not count towards your limit.
%TC:endignore

4. The Math: Why this is a "Rough Estimate with a Buffer"

TeXcount fundamentally does not count spaces because LaTeX treats spaces as formatting instructions, not printable characters. To overcome this, our scripts use the following mathematical heuristic:

Total Characters (with spaces) ≈ TeXcount Words + TeXcount Characters

Why this works:

The "Buffer" Effect:

This method is highly accurate, but it intentionally overestimates slightly. Because we add 1 space for every word, the script assumes a space exists after the very last word of a paragraph. In reality, the last word is followed by a line break, not a space.

This means for every paragraph in your document, the script overestimates your character count by exactly 1 character. Over a massive university report, this results in a tiny buffer of perhaps 50–100 characters. When adhering to strict academic limits, having a formula that pads your count by a fraction of a percent guarantees you will never accidentally submit a paper that goes over the maximum limit.