1

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.

  • It turns out it's exactly that problem, and can use exactly that solution. I did spend some time trying to use \IfSubStr to skip the need for grep, but I couldn't get the macro to handle the line containing #. And I spent some time trying to use catchfile instead 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
  • Removing the * 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
  • I hadn't noticed that's what happened. The proposed workaround adds a \def to your preamble to that effect though. – Teepeemm Jul 15 '20 at 12:29
  • After updating MiKTeX, this mwe no longer compiles on my system. – John Chris Jan 02 '21 at 17:43
  • @Teepeemm, above you write: "The proposed workaround adds a \def to your preamble". Did you post this workaround in another issue? – John Chris Jan 03 '21 at 13:20
  • I think I was referring to the accepted answer of the duplicate. – Teepeemm Jan 03 '21 at 16:45

0 Answers0