Skip to content

Instantly share code, notes, and snippets.

@jazerix
Last active May 27, 2023 12:02
Show Gist options
  • Save jazerix/f525cc7ce5ba154597cdf4ed823bb622 to your computer and use it in GitHub Desktop.
Save jazerix/f525cc7ce5ba154597cdf4ed823bb622 to your computer and use it in GitHub Desktop.
Latex Character count with spaces. Depends on the texcount library for Latex.
function countLatex{
param([string] $file)
$c = texcount .\$file.tex -char | select-string "Letters in text";
$c = [int]$c.Line.substring(17);
$w = texcount .\$file.tex | select-string "Words in text";
$w = [int]$w.Line.substring(15)
$total = $c + $w;
return $total;
}
function countLatexList{
param([array] $texFiles)
$total = 0;
$counts = @();
$texFiles | Foreach-Object { $total += $cur = countLatex($_); $counts+= $cur; }
for ($i = 0; $i -lt $texFiles.Length; $i++)
{
$cur = $counts[$i];
$percent = [math]::Round($cur / $total * 100, 2);
$text = $texFiles[$i] + ".tex: Characters (including space): $cur ($percent%)";
echo $text;
}
echo "Total: $total"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment