Dynamically count words in chapter and insert word count at start of chapter

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I am trying to adapt this suggestion of how to dynamically count words in sections, but I want to use it for a large report format doc (a thesis) where it displays a count of the words in each chapter (and at the start of the chapter, if possible).



Their solution proposes this using texcount:



documentclassarticle
newcommandwordcount
immediatewrite18 sed -e 's/+.*//'
(inputcount.txtwords)

begindocument
sectionIntroduction
In publishing and graphic design, lorem ipsum is placeholder text (filler text) commonly used to demonstrate the graphics elements of a document or visual presentation, such as font, typography, and layout. The lorem ipsum text is typically a section of a Latin text by Cicero with words altered, added and removed that make it nonsensical in meaning and not proper Latin.

wordcount
sectionMain Stuff
Even though "lorem ipsum" may arouse curiosity because of its resemblance to classical Latin, it is not intended to have meaning. Where text is comprehensible in a document, people tend to focus on the textual content rather than upon overall presentation, so publishers use lorem ipsum when displaying a typeface or design elements and page layout in order to direct the focus to the publication style and not the meaning of the text. In spite of its basis in Latin, use of lorem ipsum is often referred to as greeking, from the phrase "it's all Greek to me," which indicates that this is not meant to be readable text.

wordcount
sectionConclusion
Today's popular version of lorem ipsum was first created for Aldus Corporation's first desktop publishing program Aldus PageMaker in the mid-1980s for the Apple Macintosh. Art director Laura Perry adapted older forms of the lorem text from typography samples — it was, for example, widely used in Letraset catalogs in the 1960s and 1970s (anecdotes suggest that the original use of the "Lorem ipsum" text was by Letraset, which was used for print layouts by advertising agencies as early as the 1970s.) The text was frequently used in PageMaker templates.

wordcount
enddocument


However, my document has chapters where the main tex file works as follows:



documentclassreport
newcommandwordcount
immediatewrite18 sed -e 's/+.*//'
(inputcount.txtwords)

begindocument

chapterIntroduction
inputsections/introduction
wordcount

chapterMany Chapters
inputsections/chapters
wordcount

chapterConclusion
inputsections/conclusion
wordcount


Now I know that the wordcount command should probably sit inside the chapter files themselves, and at the start of the file if that's where I want it, but either way it fails.



And, it fails because "File 'count.tex' not found."



If it is relevant, I use atom with latex package.



Is there any way I can adapt @Jake's solution to suite my use case?



EDIT:



Following Einer's solution, of using this in a magic comment



--enable-write18


I can now get the module to count the words in the main tex file (not many, just abstract), but I still can't seem to get it to work for specific chapters or sections as per original need. If I do the original method above it just says



( words)


in the output file, like this:



like this










share|improve this question























  • I've added suggestions on how to go about fixing the grep and sed commands in my answer.
    – Einar Rødland
    19 mins ago














up vote
2
down vote

favorite












I am trying to adapt this suggestion of how to dynamically count words in sections, but I want to use it for a large report format doc (a thesis) where it displays a count of the words in each chapter (and at the start of the chapter, if possible).



Their solution proposes this using texcount:



documentclassarticle
newcommandwordcount
immediatewrite18 sed -e 's/+.*//'
(inputcount.txtwords)

begindocument
sectionIntroduction
In publishing and graphic design, lorem ipsum is placeholder text (filler text) commonly used to demonstrate the graphics elements of a document or visual presentation, such as font, typography, and layout. The lorem ipsum text is typically a section of a Latin text by Cicero with words altered, added and removed that make it nonsensical in meaning and not proper Latin.

wordcount
sectionMain Stuff
Even though "lorem ipsum" may arouse curiosity because of its resemblance to classical Latin, it is not intended to have meaning. Where text is comprehensible in a document, people tend to focus on the textual content rather than upon overall presentation, so publishers use lorem ipsum when displaying a typeface or design elements and page layout in order to direct the focus to the publication style and not the meaning of the text. In spite of its basis in Latin, use of lorem ipsum is often referred to as greeking, from the phrase "it's all Greek to me," which indicates that this is not meant to be readable text.

wordcount
sectionConclusion
Today's popular version of lorem ipsum was first created for Aldus Corporation's first desktop publishing program Aldus PageMaker in the mid-1980s for the Apple Macintosh. Art director Laura Perry adapted older forms of the lorem text from typography samples — it was, for example, widely used in Letraset catalogs in the 1960s and 1970s (anecdotes suggest that the original use of the "Lorem ipsum" text was by Letraset, which was used for print layouts by advertising agencies as early as the 1970s.) The text was frequently used in PageMaker templates.

wordcount
enddocument


However, my document has chapters where the main tex file works as follows:



documentclassreport
newcommandwordcount
immediatewrite18 sed -e 's/+.*//'
(inputcount.txtwords)

begindocument

chapterIntroduction
inputsections/introduction
wordcount

chapterMany Chapters
inputsections/chapters
wordcount

chapterConclusion
inputsections/conclusion
wordcount


Now I know that the wordcount command should probably sit inside the chapter files themselves, and at the start of the file if that's where I want it, but either way it fails.



And, it fails because "File 'count.tex' not found."



If it is relevant, I use atom with latex package.



Is there any way I can adapt @Jake's solution to suite my use case?



EDIT:



Following Einer's solution, of using this in a magic comment



--enable-write18


I can now get the module to count the words in the main tex file (not many, just abstract), but I still can't seem to get it to work for specific chapters or sections as per original need. If I do the original method above it just says



( words)


in the output file, like this:



like this










share|improve this question























  • I've added suggestions on how to go about fixing the grep and sed commands in my answer.
    – Einar Rødland
    19 mins ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I am trying to adapt this suggestion of how to dynamically count words in sections, but I want to use it for a large report format doc (a thesis) where it displays a count of the words in each chapter (and at the start of the chapter, if possible).



Their solution proposes this using texcount:



documentclassarticle
newcommandwordcount
immediatewrite18 sed -e 's/+.*//'
(inputcount.txtwords)

begindocument
sectionIntroduction
In publishing and graphic design, lorem ipsum is placeholder text (filler text) commonly used to demonstrate the graphics elements of a document or visual presentation, such as font, typography, and layout. The lorem ipsum text is typically a section of a Latin text by Cicero with words altered, added and removed that make it nonsensical in meaning and not proper Latin.

wordcount
sectionMain Stuff
Even though "lorem ipsum" may arouse curiosity because of its resemblance to classical Latin, it is not intended to have meaning. Where text is comprehensible in a document, people tend to focus on the textual content rather than upon overall presentation, so publishers use lorem ipsum when displaying a typeface or design elements and page layout in order to direct the focus to the publication style and not the meaning of the text. In spite of its basis in Latin, use of lorem ipsum is often referred to as greeking, from the phrase "it's all Greek to me," which indicates that this is not meant to be readable text.

wordcount
sectionConclusion
Today's popular version of lorem ipsum was first created for Aldus Corporation's first desktop publishing program Aldus PageMaker in the mid-1980s for the Apple Macintosh. Art director Laura Perry adapted older forms of the lorem text from typography samples — it was, for example, widely used in Letraset catalogs in the 1960s and 1970s (anecdotes suggest that the original use of the "Lorem ipsum" text was by Letraset, which was used for print layouts by advertising agencies as early as the 1970s.) The text was frequently used in PageMaker templates.

wordcount
enddocument


However, my document has chapters where the main tex file works as follows:



documentclassreport
newcommandwordcount
immediatewrite18 sed -e 's/+.*//'
(inputcount.txtwords)

begindocument

chapterIntroduction
inputsections/introduction
wordcount

chapterMany Chapters
inputsections/chapters
wordcount

chapterConclusion
inputsections/conclusion
wordcount


Now I know that the wordcount command should probably sit inside the chapter files themselves, and at the start of the file if that's where I want it, but either way it fails.



And, it fails because "File 'count.tex' not found."



If it is relevant, I use atom with latex package.



Is there any way I can adapt @Jake's solution to suite my use case?



EDIT:



Following Einer's solution, of using this in a magic comment



--enable-write18


I can now get the module to count the words in the main tex file (not many, just abstract), but I still can't seem to get it to work for specific chapters or sections as per original need. If I do the original method above it just says



( words)


in the output file, like this:



like this










share|improve this question















I am trying to adapt this suggestion of how to dynamically count words in sections, but I want to use it for a large report format doc (a thesis) where it displays a count of the words in each chapter (and at the start of the chapter, if possible).



Their solution proposes this using texcount:



documentclassarticle
newcommandwordcount
immediatewrite18 sed -e 's/+.*//'
(inputcount.txtwords)

begindocument
sectionIntroduction
In publishing and graphic design, lorem ipsum is placeholder text (filler text) commonly used to demonstrate the graphics elements of a document or visual presentation, such as font, typography, and layout. The lorem ipsum text is typically a section of a Latin text by Cicero with words altered, added and removed that make it nonsensical in meaning and not proper Latin.

wordcount
sectionMain Stuff
Even though "lorem ipsum" may arouse curiosity because of its resemblance to classical Latin, it is not intended to have meaning. Where text is comprehensible in a document, people tend to focus on the textual content rather than upon overall presentation, so publishers use lorem ipsum when displaying a typeface or design elements and page layout in order to direct the focus to the publication style and not the meaning of the text. In spite of its basis in Latin, use of lorem ipsum is often referred to as greeking, from the phrase "it's all Greek to me," which indicates that this is not meant to be readable text.

wordcount
sectionConclusion
Today's popular version of lorem ipsum was first created for Aldus Corporation's first desktop publishing program Aldus PageMaker in the mid-1980s for the Apple Macintosh. Art director Laura Perry adapted older forms of the lorem text from typography samples — it was, for example, widely used in Letraset catalogs in the 1960s and 1970s (anecdotes suggest that the original use of the "Lorem ipsum" text was by Letraset, which was used for print layouts by advertising agencies as early as the 1970s.) The text was frequently used in PageMaker templates.

wordcount
enddocument


However, my document has chapters where the main tex file works as follows:



documentclassreport
newcommandwordcount
immediatewrite18 sed -e 's/+.*//'
(inputcount.txtwords)

begindocument

chapterIntroduction
inputsections/introduction
wordcount

chapterMany Chapters
inputsections/chapters
wordcount

chapterConclusion
inputsections/conclusion
wordcount


Now I know that the wordcount command should probably sit inside the chapter files themselves, and at the start of the file if that's where I want it, but either way it fails.



And, it fails because "File 'count.tex' not found."



If it is relevant, I use atom with latex package.



Is there any way I can adapt @Jake's solution to suite my use case?



EDIT:



Following Einer's solution, of using this in a magic comment



--enable-write18


I can now get the module to count the words in the main tex file (not many, just abstract), but I still can't seem to get it to work for specific chapters or sections as per original need. If I do the original method above it just says



( words)


in the output file, like this:



like this







chapters report word-count texcount atom






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 29 mins ago

























asked 4 hours ago









ratuk_

306




306











  • I've added suggestions on how to go about fixing the grep and sed commands in my answer.
    – Einar Rødland
    19 mins ago
















  • I've added suggestions on how to go about fixing the grep and sed commands in my answer.
    – Einar Rødland
    19 mins ago















I've added suggestions on how to go about fixing the grep and sed commands in my answer.
– Einar Rødland
19 mins ago




I've added suggestions on how to go about fixing the grep and sed commands in my answer.
– Einar Rødland
19 mins ago










1 Answer
1






active

oldest

votes

















up vote
4
down vote













Assuming the file count.tex is not created, it may be that the command in write18 is not run, so you might want to ensure that you are actually running TeXcount.



First, for write18 to execute, LaTeX must be run with a command line option: --enable-write18 or --shell-escapee as explained in the TeXcount FAQ.



Next, you can try running TeXcount without the pipes, and use the option -out=filename to write the output from TeXcount directly to file: eg texcount -out=jobname.out jobname.tex to give a minimal example. If this fails, TeXcount is probably not run at all.



Maybe you need to provide the full path to texcount, although I think that would be unlikely to be a problem on Linux.



Is there any information in the LaTeX log? I think it should log that write18 is being run or not, and perhaps provide some error message if something has gone seriously wrong.




Once you have TeXcount running using write18, you might need to adjust the grep and/or sed commands to extract the correct line from the TeXcount output.



To help in doing that, it might be easiest to first run TeXcount on the command line to see what the raw output looks like, and then see what the grep and sed arguments have to be to extract the desired line of text.



Since your files lie in subfolders, you might want to verify what the value of thesection is at each relevant point.




As a side-note, there are other ways to provide per section counts. One is to run TeXcount on each included file rather than one the whole document and grep out the relevant section. Another is to use a template to customise the output from TeXcount in such a way that it produces LaTeX code: I'll see if I can find or come up with an example of how to do that.






share|improve this answer






















  • the file count.tex is now created, but it's empty (see edits to original question above)
    – ratuk_
    22 mins ago










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f453078%2fdynamically-count-words-in-chapter-and-insert-word-count-at-start-of-chapter%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
4
down vote













Assuming the file count.tex is not created, it may be that the command in write18 is not run, so you might want to ensure that you are actually running TeXcount.



First, for write18 to execute, LaTeX must be run with a command line option: --enable-write18 or --shell-escapee as explained in the TeXcount FAQ.



Next, you can try running TeXcount without the pipes, and use the option -out=filename to write the output from TeXcount directly to file: eg texcount -out=jobname.out jobname.tex to give a minimal example. If this fails, TeXcount is probably not run at all.



Maybe you need to provide the full path to texcount, although I think that would be unlikely to be a problem on Linux.



Is there any information in the LaTeX log? I think it should log that write18 is being run or not, and perhaps provide some error message if something has gone seriously wrong.




Once you have TeXcount running using write18, you might need to adjust the grep and/or sed commands to extract the correct line from the TeXcount output.



To help in doing that, it might be easiest to first run TeXcount on the command line to see what the raw output looks like, and then see what the grep and sed arguments have to be to extract the desired line of text.



Since your files lie in subfolders, you might want to verify what the value of thesection is at each relevant point.




As a side-note, there are other ways to provide per section counts. One is to run TeXcount on each included file rather than one the whole document and grep out the relevant section. Another is to use a template to customise the output from TeXcount in such a way that it produces LaTeX code: I'll see if I can find or come up with an example of how to do that.






share|improve this answer






















  • the file count.tex is now created, but it's empty (see edits to original question above)
    – ratuk_
    22 mins ago














up vote
4
down vote













Assuming the file count.tex is not created, it may be that the command in write18 is not run, so you might want to ensure that you are actually running TeXcount.



First, for write18 to execute, LaTeX must be run with a command line option: --enable-write18 or --shell-escapee as explained in the TeXcount FAQ.



Next, you can try running TeXcount without the pipes, and use the option -out=filename to write the output from TeXcount directly to file: eg texcount -out=jobname.out jobname.tex to give a minimal example. If this fails, TeXcount is probably not run at all.



Maybe you need to provide the full path to texcount, although I think that would be unlikely to be a problem on Linux.



Is there any information in the LaTeX log? I think it should log that write18 is being run or not, and perhaps provide some error message if something has gone seriously wrong.




Once you have TeXcount running using write18, you might need to adjust the grep and/or sed commands to extract the correct line from the TeXcount output.



To help in doing that, it might be easiest to first run TeXcount on the command line to see what the raw output looks like, and then see what the grep and sed arguments have to be to extract the desired line of text.



Since your files lie in subfolders, you might want to verify what the value of thesection is at each relevant point.




As a side-note, there are other ways to provide per section counts. One is to run TeXcount on each included file rather than one the whole document and grep out the relevant section. Another is to use a template to customise the output from TeXcount in such a way that it produces LaTeX code: I'll see if I can find or come up with an example of how to do that.






share|improve this answer






















  • the file count.tex is now created, but it's empty (see edits to original question above)
    – ratuk_
    22 mins ago












up vote
4
down vote










up vote
4
down vote









Assuming the file count.tex is not created, it may be that the command in write18 is not run, so you might want to ensure that you are actually running TeXcount.



First, for write18 to execute, LaTeX must be run with a command line option: --enable-write18 or --shell-escapee as explained in the TeXcount FAQ.



Next, you can try running TeXcount without the pipes, and use the option -out=filename to write the output from TeXcount directly to file: eg texcount -out=jobname.out jobname.tex to give a minimal example. If this fails, TeXcount is probably not run at all.



Maybe you need to provide the full path to texcount, although I think that would be unlikely to be a problem on Linux.



Is there any information in the LaTeX log? I think it should log that write18 is being run or not, and perhaps provide some error message if something has gone seriously wrong.




Once you have TeXcount running using write18, you might need to adjust the grep and/or sed commands to extract the correct line from the TeXcount output.



To help in doing that, it might be easiest to first run TeXcount on the command line to see what the raw output looks like, and then see what the grep and sed arguments have to be to extract the desired line of text.



Since your files lie in subfolders, you might want to verify what the value of thesection is at each relevant point.




As a side-note, there are other ways to provide per section counts. One is to run TeXcount on each included file rather than one the whole document and grep out the relevant section. Another is to use a template to customise the output from TeXcount in such a way that it produces LaTeX code: I'll see if I can find or come up with an example of how to do that.






share|improve this answer














Assuming the file count.tex is not created, it may be that the command in write18 is not run, so you might want to ensure that you are actually running TeXcount.



First, for write18 to execute, LaTeX must be run with a command line option: --enable-write18 or --shell-escapee as explained in the TeXcount FAQ.



Next, you can try running TeXcount without the pipes, and use the option -out=filename to write the output from TeXcount directly to file: eg texcount -out=jobname.out jobname.tex to give a minimal example. If this fails, TeXcount is probably not run at all.



Maybe you need to provide the full path to texcount, although I think that would be unlikely to be a problem on Linux.



Is there any information in the LaTeX log? I think it should log that write18 is being run or not, and perhaps provide some error message if something has gone seriously wrong.




Once you have TeXcount running using write18, you might need to adjust the grep and/or sed commands to extract the correct line from the TeXcount output.



To help in doing that, it might be easiest to first run TeXcount on the command line to see what the raw output looks like, and then see what the grep and sed arguments have to be to extract the desired line of text.



Since your files lie in subfolders, you might want to verify what the value of thesection is at each relevant point.




As a side-note, there are other ways to provide per section counts. One is to run TeXcount on each included file rather than one the whole document and grep out the relevant section. Another is to use a template to customise the output from TeXcount in such a way that it produces LaTeX code: I'll see if I can find or come up with an example of how to do that.







share|improve this answer














share|improve this answer



share|improve this answer








edited 21 mins ago

























answered 3 hours ago









Einar Rødland

1,06157




1,06157











  • the file count.tex is now created, but it's empty (see edits to original question above)
    – ratuk_
    22 mins ago
















  • the file count.tex is now created, but it's empty (see edits to original question above)
    – ratuk_
    22 mins ago















the file count.tex is now created, but it's empty (see edits to original question above)
– ratuk_
22 mins ago




the file count.tex is now created, but it's empty (see edits to original question above)
– ratuk_
22 mins ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f453078%2fdynamically-count-words-in-chapter-and-insert-word-count-at-start-of-chapter%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

Installing NextGIS Connect into QGIS 3?

One-line joke