The inset texcount implementation seems to conflict with titlesec package.
The desired outcome is to relieve the conflict with titlesec as well as ensuring robustness against other potential conflicts.
\documentclass{article}%
\usepackage{filecontents}%
%\usepackage{titlesec} %**** uncomment to see error message
% Compile with --enable-write18 or --shell-escape options
\immediate\write18{texcount -char -merge -tex -sum \jobname.tex | grep -i section > \jobname Count.txt} % counts characters
%\immediate\write18{texcount -merge -tex -sum \jobname.tex | grep -i section > \jobname Count.txt} % counts words
\newcommand{\limitcount}{-1}
\usepackage{xstring}
\usepackage{ifthen}
\usepackage{xcolor}
\usepackage{nameref}
\newcommand{\processCount}{%
\newread\counts
\def\zpar{\par}
\openin\counts=\jobname Count.txt
\loop
\read\counts to \sectioncount
\ifx\sectioncount\zpar\else
\showcount{\sectioncount}\
\fi
\ifeof\counts
\else
\repeat
}
\newcommand*{\showcount}[1]{%
% e.g. 67+18+0 (1/0/0/0) S[ubs]ection: The first subsection
\StrBehind{#1}{ection: }[\sectiontitleplusspace]
\StrGobbleRight{\sectiontitleplusspace}{1}[\sectiontitle]
\StrBefore{#1}{+}[\thiscount]
\expandafter\ifcsname\sectiontitle limit\endcsname%
\renewcommand{\limitcount}{\csname\sectiontitle limit\endcsname}%
\else%
\renewcommand{\limitcount}{-1}%
\fi%
\sectiontitle:
{%
\ifthenelse{\thiscount>\limitcount}{%
\textcolor{red}{\thiscount/\limitcount}%
\ifthenelse{\limitcount>-1}{%
\ (over by \number\numexpr\thiscount-\limitcount\relax)%
}{}%
}{%
\textcolor{green}{\thiscount/\limitcount}%
}%
}
}
\makeatletter
\newcommand*{\contentlimit}[1]{%
\expandafter\newcommand\csname@currentlabelname limit\endcsname{#1}
}
\makeatother
\begin{filecontents}{texcountinc.tex}
\subsection{Input section title}
\contentlimit{40}
HEy, here are some more characters.
File contents that will get input elsewhere. $a^2+b^2=c^2$.
[\frac{\sin A}a=\frac{\sin B}b=\frac{\sin C}c]
\end{filecontents*}
\begin{document}
%TC:ignore
\section*{Introduction}
\contentlimit{2000}
Content for section which has become longer and longer
%TC:endignore
\section*{Another section with subsections over limit}
\contentlimit{15}
Intro
\subsection*{The first subsection no stated limit}
This subsection has somewhat more voluminous content which tends to go on and on... and on
\subsection*{Extra spaces ignored }
\contentlimit{50}
Content aimed at testing whether math and symbols are counted: $\int$, $\Sigma$.
\section*{texcount doesn't understand lipsum}
\contentlimit{1}
Another input
\subsection*{Inputing Content}
\contentlimit{18}
\input{texcountinc}
%TC:ignore
\section*{An ignored section}
This section is ignored
% display information on document
\newpage
\section*{Count}
\processCount
%TC:endignore
\end{document}
See this question for background.
\IfSubStrto skip the need for grep, but I couldn't get the macro to handle the line containing#. And I spent some time trying to usecatchfileinstead of the manual reading, but I couldn't figure out how to go through the results line by line. Either of those would make the original process better. But this should at least get you back to working. – Teepeemm Jul 15 '20 at 03:20*from\section*and\subsection*works! (I am assuming that this is the proposed workaround). Including the patch proposed in the linked question also works - the*functionality is negated. – John Chris Jul 15 '20 at 08:58\defto your preamble to that effect though. – Teepeemm Jul 15 '20 at 12:29\defto your preamble". Did you post this workaround in another issue? – John Chris Jan 03 '21 at 13:20