
Esta pregunta es una extensión de esta pregunta sobrelistado de preguntas de directorios. Tengo el problema de que necesito entender la sección original del texto.
Salida de corriente
donde ves la segunda pregunta no tiene sentido. Fue incluido en elsubsection
Arteritis de Takayasuen el directorio Reumatología:
\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}
donde la salida actual es por este excelentecódigo
\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}
pero me gustaría que así fuera
\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}
Mi propuesta es incluir subsecciones si hay preguntas dentro de la subsección.
mi pseudocódigo
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.
El código de Terdón.
#!/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}"
donde creo que se debería cambiar la lógica de estas líneas
## Extract the wanted lines
perl -lne '$a=1 && print "" if /\\begin{question}/;
print if $a==1;
$a=0 if /\\end{question}/;' "$file"
echo ""
que utiliza una expresión regular para encontrar todas las preguntas en un archivo E ignora las subsecciones de las preguntas.
Ejemplo de datos(¡poco diferente del último caso!)
\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}
donde puede ignorar las subsubsecciones de la aplicación.
¿Cómo se puede escribir el pseudocódigo?
Se encontró un error en el código de Terdon 14.10.2014
Ejemplo de datos que causan el error.
\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}
que analizado por el código de Terdon da exactamente el mismo resultado, lo cual es incorrecto, ya que la oraciónUn 55 años..ya no debería estar ahí en el resultado final. Si hay una entrada entre la subsección y el texto del cuerpo, entonces corrija la salida. Sin embargo, esto no se puede dar por sentado.
La causa de este error son los símbolos de Windows, movidosaquí.
Respuesta1
Iba a ampliar mi código original, pero estoy llegando a un punto en el que es mucho más fácil volver a implementar todo directamente en 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";
}
}
Tenga en cuenta que esto ignora las subsecciones, pero sería fácil modificarlo para incluirlas.
Respuesta2
Ampliación o mejora del código de terdon.basado en cierta lógica en estorespuesta
#!/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'";
}
donde agregué algo de gestión de errores.