Làm cách nào để hiển thị số lượng từ trong tài liệu của tôi?
Jan 12 2021
Đối với một tạp chí, tôi phải viết một bài báo nhỏ tối đa. 700 từ. Tôi muốn có một số từ ở cuối. Tôi tìm thấy mã sau đây trên StackExchange. Nhưng khi tôi tự mình thử thì nó không hoạt động. Rất tiếc, tôi không được phép phản hồi về chủ đề này.
\documentclass{article}
\newcommand\wordcount{\input{|"texcount -inc -sum -0 -template={SUM} \jobname.tex"}}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eleifend pulvinar quam, vel suscipit urna tincidunt eget.
This document has \wordcount words.
\end{document}
Tôi nhận được lỗi sau đây:
! Lỗi LaTeX: Không tìm thấy tệp `| texcount -inc -sum -0 -template = {SUM} test.tex '.
Gõ X để thoát hoặc để tiếp tục, hoặc nhập tên mới. (Phần mở rộng mặc định: tex)
Nhập tên tệp:
Có ai biết chuyện gì đang xảy ra không?
Trả lời
1 Fran Jan 13 2021 at 04:28
![](https://post.nghiatu.com/assets/images/s/nB1Zc.png)
\documentclass{article}
\parskip1em\parindent0pt
\immediate\write18{texcount -1 -sum \jobname.tex > wordcount.aux }
\begin{document}
\section*{How to compile this file}
From the command line (The damn buttonless black window): \par
\hfil\texttt{pdflatex --shell-escape \jobname .tex}\par
From your favourite \LaTeX\ editor: \par
\hangindent1em\hangafter0 Edit your editor configuration to enable the option \texttt{--shell-escape} of the \texttt{pdflatex} compiler. You should {\em not} use this option by foreing documents (like this) without know if the source is safe.\par
% This part is not counted
%TC:ignore
Word count = {\bfseries\large \input{wordcount.aux}}
%TC:endignore
\end{document}