
이 질문은 이 질문의 확장입니다.디렉토리 질문 나열. 본문의 원문을 이해해야 하는 문제가 발생합니다.
전류 출력
두 번째 질문은 이해가 되지 않습니다. 에 포함되었습니다.subsection
다카야스 동맥염류마티스학 디렉토리:
\subsection{Takayasu arteritis}
\begin{question}
{You get a patient.
What do you notice first in this patient?}
Absence of peripheral pulse.
\end{question}
Lorem ipsum.
\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}
현재 출력은 이렇게 우수합니다.암호
\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}
하지만 난 그랬으면 좋겠어
\section{Rheumatology}
\subsection{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}
내 제안은 하위 섹션에 질문이 있는 경우 하위 섹션을 포함하는 것입니다.
내 의사코드
Look for the environment \begin{question}...\end{question}.
See the subsection of the question (it locates above the question).
If there is no subsection, leave blank.
If there are many questions within one subsection, put only one subsection.
Terdon의 코드
#!/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}"
내 생각엔 이 줄의 논리가 바뀌어야 한다고 생각해요
## Extract the wanted lines
perl -lne '$a=1 && print "" if /\\begin{question}/;
print if $a==1;
$a=0 if /\\end{question}/;' "$file"
echo ""
정규식을 사용하여 파일의 모든 질문을 찾고 질문의 하위 섹션을 무시합니다.
데이터의 예(지난번과는 조금 다릅니다!)
\subsection{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.
\subsubsection{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}
여기서 애플리케이션의 하위 섹션을 무시할 수 있습니다.
의사코드를 어떻게 작성할 수 있나요?
Terdon의 코드 14.10.2014에서 버그가 발견되었습니다.
버그를 일으키는 데이터의 예
\subsection{3}
A 55 y.o male says that for the last year ...
\begin{question}
{What is the pathogenetic mechanism of his complains?}
\end{question}
Terdon의 코드로 구문 분석하면 문장이 잘못되었기 때문에 정확히 동일한 결과를 제공합니다.55세..최종 결과에는 더 이상 존재하지 않아야 합니다. 하위 섹션과 본문 텍스트 사이에 Enter가 있는 경우 출력을 수정합니다. 그러나 이것은 가정할 수 없습니다.
이 버그의 원인은 Windows 기호로 인해 이동되었습니다.여기.
답변1
원래 코드를 확장하려고 했지만 Perl에서 모든 것을 직접 다시 구현하는 것이 훨씬 쉬운 지점에 이르렀습니다.
#!/usr/bin/env perl
## This is the path to the target directories
my $path="/Users/Masi/Dropbox/";
## The target directories
my @directories=("Cardiology","Rheumatology","Surgery");
## Iterate over the directories
foreach my $dir (@directories) {
my $dd=0;
## Read the current directory
opendir (my $DIR, "$path/$dir");
## Find all files in this directory
while (my $file = readdir($DIR)) {
## Reset the counter
my $c=0;
## Skip any files that aren't .tex
next unless $file =~ /\.tex$/;
## Open the file
open(my $fh,"$path/$dir/$file");
while (<$fh>) {
## Get the subsection. $_ is the current line.
$sub="$_" and $n=0 if /\\subsection{/;
## If this line is a question
if (/\\begin{question}/) {
## If this counter is 0, this is the first file
## of this directory, so print the section
## Print the section name
if ($dd==0) {
print "\\section{$dir}\n\n";
$dd++;
}
## If this counter is 0, this is the first question
## of this subsection, so print the subsection line
print "$sub\n" if $n==0;
$n++;
## Increment the counter, we want these lines
$c++;
## And print
print;
}
else {
## Print lines if the counter is 1
print if $c==1;
## reset the counter to 0
print "\n" and $c=0 if /\\end{question}/;
}
}
print "\n";
}
}
이는 하위 하위 섹션을 무시하지만 이를 포함하도록 수정하는 것은 쉽습니다.
답변2
terdon 코드 확장 또는 개선이것의 어떤 논리에 기초하여답변
#!/usr/bin/env perl
## This is the path to the target directories
my $path="/Users/Masi/Dropbox/";
chdir $path or die "cannot chdir '$path'";
## Iterate over the directories
foreach my $dir (
"Cardiology", "Pathophysiology", "Patology and Biopsy", "Physiology",
"Propedeutics", "Radiology", "Rheumatology", "Surgery"
)
{
my $dd=0;
## Read the current directory
opendir my $DIR, $dir or die "cannot opendir '$dir'";
## Find all files in this directory
while (my $file = readdir($DIR)) {
## Reset the counter
my $c=0;
## Skip any files that aren't .tex
next unless $file =~ /\.tex$/;
## Open the file
open(my $fh,"$path/$dir/$file");
while (<$fh>) {
## Get the subsection. $_ is the current line.
$sub="$_" and $n=0 if /\\subsection{/;
## If this line is a question
if (/\\begin{question}/) {
## If this counter is 0, this is the first file
## of this directory, so print the section
## Print the section name
if ($dd==0) {
print "\\section{$dir}\n\n";
$dd++;
}
## If this counter is 0, this is the first question
## of this subsection, so print the subsection line
print "$sub\n" if $n==0;
$n++;
## Increment the counter, we want these lines
$c++;
## And print
print;
}
else {
## Print lines if the counter is 1
print if $c==1;
## reset the counter to 0
print "\n" and $c=0 if /\\end{question}/;
}
}
print "\n";
}
closedir $DIR or die "cannot closedir '$dir'";
}
여기에 오류 관리를 추가했습니다.