我正在做一个 Makefile,我每天在 0230 通过 Crontab 定期运行它
crontab -e; 30 2 * * * /bin/thePseudocode
类似Python的伪代码
directories = ["Cardiology", "Rheumatology", "Surgery"]
for directory in directories
files = directory.files(); % not sure if such a parameter exists
files = files.match(.*tex); % trying to get only tex files; not sure if match exists
summaryFile = "";
for texFile in files
summaryFile.add( ...
textFile.match( (?s)\\begin{question}.*?\\end{question} ) ...
)
% Solution based on this thread
% Problem in writing this Regex in Perl http://unix.stackexchange.com/questions/159307/to-match-only-innermost-environment-by-regex
end
end
save this `summaryFile` as /Users/Masi/Dropbox/QuestionSummary.tex
其中files
是目录中所有文件的列表,summaryFile
是列出所有 tex 文件中所有问题的文件。那些文件,我想最终编译pdf乳胶每天早上用pdf阅读器阅读。
位于文件夹中的示例文件风湿病学
\section{Takayasu arteritis}
\begin{question}
{You get a patient.
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}
\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye.
So special eye diagnosis done.
Affects eye.
\end{question}
Fever of unknown origin can be used when you do not know what is causing the disease.
% Show cases in MedScape and ask class.
Aneurysms.
\subsection{Treatment}
\begin{question}
{What you should always include in Takayasu treatment?
What are the symptoms?}
Blood pressure.
Aneurysms which will burst without treatment.
So blood pressure decreasing drugs like beta blockers along in combination with other drugs.
\end{question}
\begin{question}
{When is the checkup of the Takayasu arteritis?}
Only once per year.
You could expect every month like normally in this kind of diseases.
But only once per year.
\end{question}
其中输出应针对文件夹中的所有文件
\section{Rheumatology}
\begin{question}
{You get a patient.
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}
\begin{question}
{What was the first Takayasu case?}
Young woman in Asia with red vessels in the eye.
So special eye diagnosis done.
Affects eye.
\end{question}
\begin{question}
{What you should always include in Takayasu treatment?
What are the symptoms?}
Blood pressure.
Aneurysms which will burst without treatment.
So blood pressure decreasing drugs like beta blockers along in combination with other drugs.
\end{question}
\begin{question}
{When is the checkup of the Takayasu arteritis?}
Only once per year.
You could expect every month like normally in this kind of diseases.
But only once per year.
\end{question}
生成文件
all:
pdflatex /Users/Masi/Dropbox/QuestionsSummary.tex /Users/Masi/Dropbox/QuestionsSummary.pdf
pdflatex /Users/Masi/Dropbox/QuestionsSummary.tex /Users/Masi/Dropbox/QuestionsSummary.pdf % to compile a few times to be successful
pdflatex
% I am not sure if I should have some error management, since often the pdflatex crashes
% So pdflatex is not probably the right tool to go
如何在您喜欢的任何工具中编写这样的伪代码? 我喜欢 Python,但不会完全依靠它。
答案1
如果我理解正确的话,您正在寻找这样的东西(在bash
):
#!/usr/bin/env bash
## avoid errors if a directory has no *tex files
shopt -s nullglob
directories=("Cardiology" "Rheumatology" "Surgery");
## Change this to set whichever options you want.
printf "%s\n%s\n" "\documentclass{YOURCLASS}" "\begin{document}"
for directory in ${directories[@]}
do
## Reset the counter, avoid empty sections.
c=0;
for file in "$directory"/*tex
do
let c++
[ "$c" -eq 1 ] && printf "\n%s\n" "\section{$directory}"
## Extract the wanted lines
perl -lne '$a=1 && print "" if /\\begin{question}/;
print if $a==1;
$a=0 if /\\end{question}/;' "$file"
echo ""
done
done
echo "\end{document}"
如果您从包含 Cardiology 等的目录运行该脚本,它应该提供如下输出: