# change dir: cd 'F:/School/Vycislitelnost I/MojePoznamky'
# run this command: ./wikiToLatex.ps1 ./wikiText.txt

param([string]$file)

$text = [string]::join([environment]::newline, (Get-Content "$file" -Encoding UTF8))
# </math>  -> $
$text = [regex]::Replace($text, "</math>", "$", [Text.RegularExpressions.RegExOptions]::Multiline)
# <math>   -> $
$text = [regex]::Replace($text, "<math>", "$", [Text.RegularExpressions.RegExOptions]::Multiline)
# \mathbb{  -> \mathbbm{  + \usepackage{bbm}
$text = [regex]::Replace($text, "\\mathbb\{", "\mathbbm{", [Text.RegularExpressions.RegExOptions]::Multiline)

# &ndash  -> --
$text = [regex]::Replace($text, "&ndash;", "--", [Text.RegularExpressions.RegExOptions]::Multiline)

# &mdash  -> --
$text = [regex]::Replace($text, "&mdash;", "--", [Text.RegularExpressions.RegExOptions]::Multiline)

# ''text'' -> \emph{text}
$text = [regex]::Replace($text, "\'\'([^']+)\'\'", '\mathit{$1}', [Text.RegularExpressions.RegExOptions]::Multiline)


# === text === -> \subsection{text}
$text = [regex]::Replace($text, "=== ([^=]+) ===", '\subsection{$1}'+"`n", [Text.RegularExpressions.RegExOptions]::Multiline)

# == text == -> \section{text}
$text = [regex]::Replace($text, "== ([^=]+) ==", '\section{$1}'+"`n", [Text.RegularExpressions.RegExOptions]::Multiline)

# == text == -> \section{text}
$text = [regex]::Replace($text, "'\mathit{", '\emph{', [Text.RegularExpressions.RegExOptions]::Multiline)


$text

$text | Out-File -Encoding UTF8 "$file.tex"
