Code: Select all
\newcounter{words}
\newenvironment{counted}{%
\noindent\hrulefill\par
\marginpar{\footnotesize\textit{Begin counting words}}
\setcounter{words}{0}
\SearchList!{wordcount}{\stepcounter{words}}
{a?,b?,c?,d?,e?,f?,g?,h?,i?,j?,k?,l?,m?,
n?,o?,p?,q?,r?,s?,t?,u?,v?,w?,x?,y?,z?}
\UndoBoundary{'}
\SearchOrder{p;}}{%
\StopSearching\marginpar{\footnotesize\textit{\thewords\ words}}
\noindent\hrulefill}
I'd like to reverse the order of the marginal notes so that the word count appears at the beginning of the environment rather than at the end. However, simply reversing the order of the margin notes (as in the snippet below) does not have the desired effect. The count is 0 at the time the first margin note is printed.
Code: Select all
\newcounter{words}
\newenvironment{counted}{%
\noindent\hrulefill\par
\marginpar{\footnotesize\textit{\thewords\ words}}
\setcounter{words}{0}
\SearchList!{wordcount}{\stepcounter{words}}
{a?,b?,c?,d?,e?,f?,g?,h?,i?,j?,k?,l?,m?,
n?,o?,p?,q?,r?,s?,t?,u?,v?,w?,x?,y?,z?}
\UndoBoundary{'}
\SearchOrder{p;}}{%
\StopSearching
\marginpar{\footnotesize\textit{End counting words}}
\noindent\hrulefill}
Below is a full MWE which separates out the environment definition from my personalized class file and provides a test case. The last line in the body of the text shows what the word count should be.
Code: Select all
% !TEX program = XeLaTeX
\documentclass{article}
\usepackage{xesearch}
\newcounter{words}
\newenvironment{counted}{%
\noindent\hrulefill\par
\marginpar{\footnotesize\textit{\thewords\ words}}
\setcounter{words}{0}
\SearchList!{wordcount}{\stepcounter{words}}
{a?,b?,c?,d?,e?,f?,g?,h?,i?,j?,k?,l?,m?,
n?,o?,p?,q?,r?,s?,t?,u?,v?,w?,x?,y?,z?}
\UndoBoundary{'}
\SearchOrder{p;}}{%
\StopSearching
\marginpar{\raggedright\footnotesize\textit{End counting words}}
\par\noindent\hrulefill}
\begin{document}
\begin{counted}
In order to better understand this sentence we will expand the predicate by replacing each term with its definition. “Reverence” is an intentional action directed towards an object (using “object” in the broadest sense of the word so that it includes everything which can be thought of) for the purpose of honoring that object and/or acknowledging the subordination of the subject to the object (the actual mix being determined on a case-by-case basis). The modification by “natural” in the sentence indicates that this action is not one which is learned, but rather arises from the essence of the subject performing the action. The possessive “mind's” further modifies this action to indicate that it is one involving the active mental faculties. Further it restricts the possible domain of subjects to those which possess said active mental faculties. Putting all this together, the predicate can be expanded as “the intentional actions of a being with active mental faculties which direct said faculties towards an object for the purpose of honoring or subordinating the subject to said object and which arise from the essence of the being possessing said faculties.”
\end{counted}
The above response contains \thewords\ words.
\end{document}