forked from phc/dm-scripts
aggiunto nuovo script tex_to_md
This commit is contained in:
@@ -93,3 +93,15 @@ Questa repository contiene i seguenti script:
|
||||
```
|
||||
|
||||
Questo script è stato utilizzato per creare dei riassunti di Geometria 2 da delle dispense più complete: [G2-cheat-sheet](https://github.com/lukefleed/G2-cheat-sheet)
|
||||
|
||||
- `tex_to_md` — [@lukefleed](https://git.phc.dm.unipi.it/lukefleed)
|
||||
|
||||
Script che prende in input un file `.tex` da in output un file `.md` contenente un elenco puntato di tutte le definizioni, teoremi e proposizioni presenti nel file `.tex`. Utile per creare un riassunto degli argomenti di un corso da utilizzare per preparare l'orale.
|
||||
|
||||
Utilizzo:
|
||||
|
||||
```bash
|
||||
tex_to_md <input.tex> <output.md>
|
||||
```
|
||||
|
||||
Qui un esempio di utilizzo: [Argomenti di G2](https://git.phc.dm.unipi.it/lukefleed/domande-orali/src/branch/master/geoemtria-2)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Usage: $0 input.tex output.md"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
input_file="$1"
|
||||
output_file="$2"
|
||||
|
||||
# Funzione per convertire le sezioni
|
||||
convert_section() {
|
||||
local level=$1
|
||||
local name=$2
|
||||
echo -e "$(printf '#%.0s' $(seq 1 $level)) $name\n" >> "$output_file"
|
||||
}
|
||||
|
||||
# Funzione per convertire definizioni, teoremi e proposizioni
|
||||
convert_definition_or_theorem_or_proposition() {
|
||||
local type=$1
|
||||
local name=$2
|
||||
if [[ $type == "teorema" || $type == "proposizione" ]]; then
|
||||
echo "* [ ] [**$type**] $name" >> "$output_file"
|
||||
else
|
||||
echo "* [ ] [$type] $name" >> "$output_file"
|
||||
fi
|
||||
}
|
||||
|
||||
# Inizializza il file di output
|
||||
> "$output_file"
|
||||
|
||||
# Leggi il file .tex e converti le sezioni, definizioni, teoremi e proposizioni
|
||||
while IFS= read -r line; do
|
||||
if [[ $line =~ \\section\{(.+)} ]]; then
|
||||
convert_section 1 "${BASH_REMATCH[1]}"
|
||||
elif [[ $line =~ \\subsection\{(.+)} ]]; then
|
||||
convert_section 2 "${BASH_REMATCH[1]}"
|
||||
elif [[ $line =~ \\subsubsection\{(.+)} ]]; then
|
||||
convert_section 3 "${BASH_REMATCH[1]}"
|
||||
elif [[ $line =~ \\begin\{definition\}\[(.+)\] ]]; then
|
||||
convert_definition_or_theorem_or_proposition "definizione" "${BASH_REMATCH[1]}"
|
||||
elif [[ $line =~ \\begin\{theorem\}\[(.+)\](\{.+})? ]]; then
|
||||
convert_definition_or_theorem_or_proposition "teorema" "${BASH_REMATCH[1]}"
|
||||
elif [[ $line =~ \\begin\{proposition\}\[(.+)\] ]]; then
|
||||
convert_definition_or_theorem_or_proposition "proposizione" "${BASH_REMATCH[1]}"
|
||||
fi
|
||||
done < "$input_file"
|
||||
Reference in New Issue
Block a user