summaryrefslogtreecommitdiff
path: root/texmf-dist/doc/latex/thorshammer/system-scripts/thors-structure/thmclass.ps1
blob: 2dcbc65c25130f103e89346cae1b0d96b7c90907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
# Version 1.3 changes
# =====================================================================================================
# copyka.ps1 allows a comment character (#)
# delka.ps1 allows a comment character (#)
# =====================================================================================================
# Version 1.2 changes
# =====================================================================================================
# removed moveka.ps1
# removed old version comments
# added template for altclasspath
# removed .ps1 from BAT helper file, that way one can easiear hit TAB for autocompletion in comamnd shell
# OPEN line 92: copyka.ps1 --> lines starting with # are *not* ignored at least here
# Workaround does not help: (get-content ./altclasspaths.txt) -notmatch '^#' WHY?

# =====================================================================================================
#
# This script makes a custom class folder for thorshammer with
# needed folders, adjusted path settings and templates for tex, cfg etc.
#
# Set path for thorshammer (local texmf dir} for Windows/Linux
# This has to be done only once
$pathThorshammerWin="C:\Users\$env:UserName\texmf\tex\latex\thorshammer" # Windows
$pathThorshammerWin="C:\Users\Public\Documents\My TeX Files\tex\latex\aeb\thorshammer"
$pathThorshammerLin="/home/manjothor/texmf/tex/latex/thorshammer" # Linux

# Store the system locale in a var. We need them later in the script for localization
$locale = Get-UICulture
$myLocale = "de"

# Remove everything to the left of a comment character, then trim
function Strip-and-Trim {
  param([string]$str)
  $pos=$str.IndexOf("#")
  If($pos -ne -1) {
    $str=$str.substring(0,$pos)
  }
  $str=$str.trim()
  return $str
}
Write-Host "There are" $args.Length "arguments";
$argList=@()
$listOfEight=$args[0]
if(Test-Path -Path ./$listOfEight) {
  get-content $args[0] | %{
    Write-Host "Line: $_"
    $argList+=$_
  }
  $class = Strip-and-Trim($argList[0])
  $number = Strip-and-Trim($argList[1])
  $subject = Strip-and-Trim($argList[2])
  $theme = Strip-and-Trim($argList[3])
  $instrName = Strip-and-Trim($argList[4])
  $date = Strip-and-Trim($argList[5])
  $time = Strip-and-Trim($argList[6])
  $classPath= Strip-and-Trim($argList[7])

# Remove whitespace in $class and $instrName because we don't need whitespace
# in this two vars.
  $class = $class.replace(' ','')
  $instrName = $instrName.replace(' ','')

############
# folders  #
############
  New-Item $class -ItemType directory
  cd $class
  New-Item $instrName -ItemType directory
  Set-Location "$instrName"
  New-Item backup -ItemType directory
  If ($locale -like "*$myLocale*") {
      New-Item vonSUS -ItemType directory
      New-Item anSUS -ItemType directory
  } else {
      New-Item fromStudents -ItemType directory
      New-Item toStudents -ItemType directory
  }
} else {
  Write-Host "The file" $listOfEight "cannot be found in the current folder," `
"check the spelling, include the extension."
  exit
}

##############
# copyscript #
##############
# Version 1.3
New-Item copyka.ps1 -ItemType file
Set-Content ./copyka.ps1 '# Get-ExecutionPolicy
# Set-ExecutionPolicy RemoteSigned
# This script copies PDFs from the $startLocation to $instrDest, but only
# if in a $instrName folder
#
# Strip-and-Trim function
# Remove everything to the left of a comment character, then trim
function Strip-and-Trim {
  param([string]$str)
  $pos=$str.IndexOf("#")
  If($pos -ne -1) {
    $str=$str.substring(0,$pos)
  }
  $str=$str.trim()
  return $str
}
# vars
$instrName="#instrName"
$startLocations=@("#classPath")
Write-Host ""
if(Test-Path -Path ./altclasspaths.txt) {
  get-content ./altclasspaths.txt | %{
    $str= Strip-and-Trim($_)
    if($str) {	  
      Write-Host "Reading alternate path: $str"
      $startLocations+=$str
    }
  }
}
$instrDest="$PWD\#from"
#
# script starts here
#
$currentPath=Convert-Path .
foreach ($startLocation in $startLocations) {
  Set-Location $startLocation
  $numCopied=0
  Write-Host "`nCopying any PDFs files from within a `"$instrName`" subfolder of `
`"$startLocation`" to `
`"$instrDest`""
  Get-ChildItem -Path . -Filter "*.pdf" -Recurse |
  Where-Object { $_.DirectoryName -match $instrName } -OutVariable fileName |
  Copy-Item -Destination $instrDest
  if ($fileName.Name -eq $null) {Write-Host "`nNo files to copy"}
  else {
    Write-Host "`nReport:"
    $numCopied=$fileName.Name.Count
    $fileName.Name
  }
  Write-Host @( Get-ChildItem $PWD ).Count "folders examined, $numCopied files copied"
  cd $currentPath
}'
# replace markers with content of vars: #instrName, #classPath
(Get-Content -Path .\copyka.ps1) | ForEach-Object {
	$_ -Replace '#instrName', $instrName `
	   -Replace '#classPath', $classPath } | Set-Content -Path .\copyka.ps1 -encoding UTF8

If ($locale -like "*$myLocale*") {
    (Get-Content -Path .\copyka.ps1) | ForEach-Object {
        $_ -Replace '#from', 'vonSUS' } | Set-Content -Path .\copyka.ps1 -encoding UTF8
} else {
    (Get-Content -Path .\copyka.ps1) | ForEach-Object {
        $_ -Replace '#from', 'fromStudents' } | Set-Content -Path .\copyka.ps1 -encoding UTF8
}

#################
# delete script #
#################
# Version 1.3
Set-Content ./delka.ps1 '# Get-ExecutionPolicy
# Set-ExecutionPolicy RemoteSigned
# This script removes (deletes) PDFs from the $startLocation, but only if in a $instrName folder
#
# Strip-and-Trim function
# Remove everything to the left of a comment character, then trim
function Strip-and-Trim {
  param([string]$str)
  $pos=$str.IndexOf("#")
  If($pos -ne -1) {
    $str=$str.substring(0,$pos)
  }
  $str=$str.trim()
  return $str
}# vars
#
$instrName="#instrName"
$startLocations=@("#classPath")
Write-Host ""
if(Test-Path -Path ./altclasspaths.txt) {
  get-content ./altclasspaths.txt | %{
    $str= Strip-and-Trim($_)
    if($str) {	  
      Write-Host "Reading alternate path: $str"
      $startLocations+=$str
    }
  }
}
$instrDest="$PWD\#from"
#
# script starts here
#
$currentPath=Convert-Path .
foreach ($startLocation in $startLocations) {
  Set-Location $startLocation
  $numDel=0
  Write-Host "`nDeleting the following PDFs files from within a `"$instrName`" subfolder of `
`"$startLocation`""
  Get-ChildItem -Path . -Filter "*.pdf" -Recurse |
    Where-Object { $_.DirectoryName -match $instrName } -OutVariable fileName | 
	Remove-Item
  if ($fileName.Name -eq $null) {Write-Host "`nNo files to delete"}
  else {
    Write-Host "`nReport: deleting files,"
    $numDel=$fileName.Name.Count
    $fileName.Name
  }
  Write-Host @( Get-ChildItem $PWD ).Count "folders examined, $numDel files deleted"
   cd $currentPath
}'
# replace markers with content of vars: #instrName, #classPath
(Get-Content -Path .\delka.ps1) | ForEach-Object {
	$_ -Replace '#instrName', $instrName `
	   -Replace '#classPath', $classPath } | Set-Content -Path .\delka.ps1 -encoding UTF8

If ($locale -like "*$myLocale*") {
    (Get-Content -Path .\delka.ps1) | ForEach-Object {
        $_ -Replace '#from', 'vonSUS' } | Set-Content -Path .\delka.ps1 -encoding UTF8
} else {
    (Get-Content -Path .\delka.ps1) | ForEach-Object {
        $_ -Replace '#from', 'fromStudents' } | Set-Content -Path .\delka.ps1 -encoding UTF8
}

##Begin Version 1.2
##########################
# altclasspaths template #
##########################
Set-Content ./altclasspaths.txt -encoding UTF8 '# C:\Users\IEUser\Desktop\TestClass1'

##End Version 1.2

#############################
# csv to cfg convert script #
#############################
Set-Content ./csvTOcfg.ps1 '# Make a complete cfg for thorshammer package from a csv list
# accepted list delimiters: , or ;. Spaces ar not allowed! Replace all german umlauts
# with ue, oe, ae, ss to avoid problems with thorshammer package
#
# Example list:
# First Name|Last Name|Folder
# Anton;Müller;AM29914M
#\classMember{Anton}{Mueller}{AM299/instructor-name}
# Anton;Müller;*C:/.../AM299
#\classMember{Anton}{Mueller}*{C:/.../AM299/instructor-name}
#
If ( $args.Length -eq 0 ) {
  Write-Host "A CSV file of the class members is required," `
    "see documentation"
  exit
} else {
  $listName=$args[0]
  if(Test-Path -Path ./$listName.csv) {
    } else {
      Write-Host "Cannot find the file `"$listName.csv`" in the current folder," `
        "check the spelling, do not include the extension."
      exit
  }
}'
######################
# Script starts here #
######################'
# Now append the script itself, this way we have to maintain only one script
# Remark: we must escape $ and ` with `$ and ``
Add-Content ./csvTOcfg.ps1 @"
get-content "`$listName.csv" | foreach {
"\classMember{" + `$_ ``
+ "/`#instrName}" ``
-Replace ";", "}{" ``
-Replace ",","}{" ``
-Replace "{\*", "*{" } | Set-Content "convertedList.cfg"

# Store convertedList.cfg in a variable
`$convertedListCfg = get-content .\convertedList.cfg -Raw

# function to replace umlauts
# https://www.datenteiler.de/powershell-umlaute-ersetzen/
function Replace-Umlaute ([string]`$s) {
    `$UmlautObject = New-Object PSObject | Add-Member -MemberType NoteProperty -Name Name -Value `$s -PassThru

    # hash tables are by default case insensitive
    # we have to create a new hash table object for case sensitivity

    `$characterMap = New-Object system.collections.hashtable
    `$characterMap.ä = "ae"
    `$characterMap.ö = "oe"
    `$characterMap.ü = "ue"
    `$characterMap.ß = "ss"
    `$characterMap.Ä = "Ae"
    `$characterMap.Ü = "Ue"
    `$characterMap.Ö = "Oe"

    foreach (`$property  in "Name") {
        foreach (`$key in `$characterMap.Keys) {
            `$UmlautObject.`$property = `$UmlautObject.`$property -creplace `$key,`$characterMap[`$key]
        }
    }
    `$UmlautObject
}

# replace umlauts in $convertedList.cfg and make a correctedListCfg
`$correctedListCfg = Replace-Umlaute "`$convertedListCfg"
`$correctedListCfg.Name

# Finally append correctedListCfg to desired
# cfg file, usually $class.cfg
add-content "..\`#class" `$correctedListCfg.Name
Remove-Item convertedList.cfg
"@

# Set correct class name
(Get-Content "csvTOcfg.ps1") | ForEach-Object {
    $_ -Replace '#class', "00-$class.cfg" `
      -Replace  '#instrName', $instrName } | Set-Content "csvTOcfg.ps1" -encoding UTF8

######################
# General helper BAT #
######################
New-Item "runps1.bat" -ItemType file
Set-Content "runps1.bat" `
'rem echo "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
PowerShell.exe -ExecutionPolicy Bypass -Command "& ''./%1'' %2"' ##Begin Version 1.2

##################
# class folders  #
##################
New-Item classFolders.ps1 -ItemType file
Set-Content ./classFolders.ps1 '# Create class folders
If ( $args.Length -eq 0 ) {
  Write-Host "A CVS file of the class members is required," `
    "see documentation"
  exit
} else {
  $listName=$args[0]
  if(Test-Path -Path ./$listName.csv) {
    } else {
      Write-Host "Cannot find the file `"$listName.csv`" in the current folder," `
        "check the spelling, do not include the extension."
      exit
  }
}
get-content "$listName.csv" | foreach {
$_ +">#instrName" -Replace ";","," } | Set-Content "commaList.csv"

$argList=@()
get-content "commaList.csv" | %{
# Write-Host "$_"
  $split=$_.split(",")
# Write-Host $split[2]
  $argList+=$split[2]
}
$currentPath=Convert-Path .
cd "#classPath"
Write-Host "Creating folder structure at `"#classPath`"," `
  "with some exceptions"
for ($i=0; $i -lt $argList.length; $i++) {
	$arg=$argList[$i]
	$splitTwo=$argList[$i].split(">")
	$firstName=$splitTwo[0]
	$secondName=$splitTwo[1]
  if ($firstName[0] -eq "*") {
    $arg=$arg.substring(1)
    $msg="Parsing the full path $arg" -Replace ">","/"
    Write-Host $msg
    Write-Host "Creating exceptional folders"
    $firstName=$firstName.substring(1)
#Write-Host "$firstName"
    Write-Host "  Creating folder: $firstName"
    New-Item $firstName -ErrorAction:Ignore -ItemType directory
    $secondName=$firstName+"/$secondName"
#Write-Host "$secondName"
    Write-Host "  Creating folder: $secondName"
    New-Item $secondName -ErrorAction:Ignore -ItemType directory
  } else {
  	$msg="Parsing the relative path $arg" -Replace ">","/"
  	Write-Host $msg
  	Write-Host "  Creating folder: $firstName"
  	New-Item $firstName -ErrorAction:Ignore -ItemType directory
  	cd $firstName
  	Write-Host "  Creating subfolder of $firstName named: $secondName"
  	New-Item $secondName -ErrorAction:Ignore -ItemType directory
  	cd ..
  }
}
cd $currentPath
Remove-Item commaList.csv'
#
# replace markers with content of vars: #instrName, #classPath
(Get-Content -Path .\classFolders.ps1) | ForEach-Object {
	$_ -Replace "#instrName", $instrName `
	   -Replace "#classPath", $classPath } | Set-Content -Path .\classFolders.ps1

############################
# Sample csv file          #
############################
New-Item sample-list.csv -ItemType file
Set-Content ./sample-list.csv `
'Mühle;Wäter;MW634B
Anton,Müller,AM256M
Laura,Vögt,LM356B'

###########################################
# copy container.pdf, terminate-batch.pdf #
###########################################
If (Test-Path $pathThorshammerWin) {
    Copy-Item "$pathThorshammerWin\container.pdf" -Destination "$PWD"
    Copy-Item "$pathThorshammerWin\terminate-batch.pdf" -Destination "$PWD"
}
If (Test-Path $pathThorshammerLin){
Copy-Item "$pathThorshammerLin/container.pdf" -Destination "$PWD"
Copy-Item "$pathThorshammerLin/terminate-batch.pdf" -Destination "$PWD"
}

################
# tex template #
################
cd ..
New-Item "tex-template.tex" -ItemType file

If ($locale -like "*$myLocale*") {
# German ######################################
Set-Content "tex-template.tex" '%% Customize template ! %%
\documentclass[fontsize=11pt]{scrartcl}
\usepackage[%
german,
pro,
usesf,
navibar,
forcolorpaper
%forpaper
]{web}
\usepackage[top=20mm,left=20mm,right=20mm,bottom=25mm]{geometry}
\usepackage[usesumrytbls,allowrandomize]{exerquiz}
\usepackage{ran_toks}
\usepackage[%
% usebatch    % copy to class folder
batchdistr    % only copy to instructors folder
% testmode    % testing quizzes
]{thorshammer}
\hypersetup{pdfencoding=auto}          % include or remove hyperref options
%\usepackage{thorshammerConf}          % place your own sty file here
\usepackage[autostyle=true]{csquotes}  % change quotes globally

\DeclareQuiz{q#number}
\setInitMag{fitwidth}
\hypersetup{pdfpagelayout=OneColumn}
\reversemarginpar
% It is important to freeze the seed to that (1) you can reproduce the exact
% same quiz at a later time; (2) allow content written to the AUX file to
% come up to date. This is important when using summary tables.
\useThisSeed{1344524586}

% Class Path
\InputClassData{00-#class}
\autoCopyOn
% \autoCopyOff

% Cover pages
%\DeclareCoverPage{0}

% Header settings
\thQzName{#theme}                   % Thema
\thQzHeaderL{#class}                % Klasse
\thQzHeaderCQ{#subject: \thqzname}
\thQzHeaderCS{Lösungen: \thqzname}

% Title
\title{#class}
\subject{#subject}
\author{#instrName}
\keywords{#time}
\university{Freiherr-vom-Stein-Berufskolleg} % change to your institution
\version{#number}
\copyrightyears{#date}

% input web.cfg (again) to declare or define commands
\inputWebCfg

\begin{makeClassFiles}
\sadMultQuizzes
\end{makeClassFiles}

\begin{document}
\makeinlinetitle
% Instructions

% Declare Quiz bodys
\declareQuizBody{qzbody1}
%\declareQuizBody{qzbody2}
%\declareQuizBody{qzbody3}
%\declareQuizBody{qzbody4}

\begin{qzbody1}
\bRTVToks{\currQuiz}
% Change margin settings for summary tables, and set it back after
% \thQuizHeader execution
\newgeometry{top=20mm,left=30mm,right=20mm,bottom=25mm}
\thQuizHeader
\newgeometry{top=20mm,left=20mm,right=20mm,bottom=25mm}

\begin{quiz*}{\currQuiz}
% Bearbeiten Sie folgende Aufgaben.
\begin{questions}
\begin{rtVW}
\section{myTitle}
\item\PTs{2} my question text

\end{rtVW}

%% Change nothing here %%
\eRTVToks\displayListRandomly{\thisQuiz}
\end{questions}
\writeProListAux
\end{quiz*}\quad\thQuizTrailer
\end{qzbody1}
% Randomize questions Now we input the qzbody back in two times, though it can
% be more than that. The quiz name modified in each instance. Each instance of
% the quiz has a randomized order
%
\InputQuizBody{qzbody1}
%\InputQuizBody{qzbody1}
%\InputQuizBody{qzbody1}
%\InputQuizBody{qzbody2}
\end{document}'
###########################################
} else {
# English #################################
Set-Content "tex-template.tex" '%% Customize template ! %%
\documentclass{article}
\usepackage{amstext}
\usepackage{web}
\usepackage[usesumrytbls,allowrandomize]{exerquiz}
\usepackage{ran_toks}
\usepackage[usebatch]{thorshammer}

\DeclareQuiz{q#number}

% It is important to freeze the seed to that (1) you can reproduce the exact
% same quiz at a later time; (2) allow content written to the AUX file to
% come up to date. This is important when using summary tables.
\useThisSeed{1344524586}

\setInitMag{fitwidth}
\hypersetup{pdfencoding=auto}
\reversemarginpar

\showCreditMarkup

\useBeginQuizButton[\CA{Begin}]
\useEndQuizButton[\CA{End}]
\PTsHook{($\eqPTs^{\text{pts}}$)}
\useMCCircles

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For headers, title and other fine grained settings %
% refer to the thorshammer doku!                     %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Class Path
\InputClassData{00-#class}
\autoCopyOn
% \autoCopyOff

% Cover pages
%\DeclareCoverPage{0}

% Header settings
\thQzName{#theme}                   % topic
\thQzHeaderL{#class}                % class
\thQzHeaderCQ{#subject: \thqzname}
\thQzHeaderCS{Solutions: \thqzname}

% Title
\title{#class}
\subject{#subject}
\author{#instrName}
\keywords{#time}
\university{AcroTeX.edu} % change to your institution
\version{#number}
\copyrightyears{#date}

% input web.cfg (again) to declare or define commands
\inputWebCfg

\begin{makeClassFiles}
\sadMultQuizzes
\end{makeClassFiles}

\begin{document}
\declareQuizBody{qzbody1}
\begin{qzbody1}

\bRTVToks{\currQuiz}

\thQuizHeader

% Instructions
\begin{quiz*}{\currQuiz}
Solve each of these problems, passing is 100\%.
\begin{questions}
\begin{rtVW}
  \item\PTs{3} Answer the question...

\end{rtVW}
%% Change nothing here %%
\eRTVToks
\displayListRandomly{\thisQuiz}
\end{questions}
\writeProListAux
\end{quiz*}\quad\thQuizTrailer
\end{qzbody1}
% Randomize questions Now we input the qzbody back in two times, though it can
% be more than that. The quiz name modified in each instance. Each instance of
% the quiz has a randomized order
%
\InputQuizBody{qzbody1}
%\InputQuizBody{qzbody1}
%\InputQuizBody{qzbody1}
%\InputQuizBody{qzbody2}
\end{document}'
}

###################################
# Generate TEX file from template #
###################################
New-Item "genquiz.ps1" -ItemType file
Set-Content "genquiz.ps1" `
'# Remove everything to the left of a comment character, then trim
function Strip-and-Trim {
  param([string]$str)
  $pos=$str.IndexOf("#")
  If($pos -ne -1) {
    $str=$str.substring(0,$pos)
  }
  $str=$str.trim()
  return $str
}
$argList=@()
get-content ../#varsList | %{
      Write-Host "Line: $_"
      $argList+=$_
  }
$class = Strip-and-Trim($argList[0])
$number = Strip-and-Trim($argList[1])
$subject = Strip-and-Trim($argList[2])
$theme = Strip-and-Trim($argList[3])
$instrName = Strip-and-Trim($argList[4])
$date = Strip-and-Trim($argList[5])
$time = Strip-and-Trim($argList[6])
$classPath= Strip-and-Trim($argList[7])

$templateName="$number-$class-$subject.tex"
Copy-Item ./tex-template.tex ./$templateName

# replace markers with vars
(Get-Content $templateName) | ForEach-Object {
	$_ -Replace ''#instrName'', $instrName `
	   -Replace ''#class'', $class `
	   -Replace ''#time'', $time `
	   -Replace ''#number'', $number `
	   -Replace ''#theme'', $theme `
	   -Replace ''#subject'', $subject `
	   -Replace ''#date'', $date } | Set-Content $templateName -encoding UTF8`
# Remove whitespace and umlauts from file name
Get-ChildItem *.tex | Rename-Item -NewName {
    $_.Name -replace '' '',''-'' `
      -replace ''ä'',''ae'' `
      -replace ''ö'',''oe'' `
      -replace ''ü'',''ue'' `
      -replace ''ß'',''ss'' }'
(Get-Content "genQuiz.ps1") | ForEach-Object {
	$_ -Replace '#varsList', $listOfEight } | Set-Content "genQuiz.ps1"
# Remove whitespace from tex template file
Get-ChildItem *.tex | Rename-Item -NewName { $_.Name -replace ' ','-' }

######################
# General helper BAT #
######################
New-Item "runps1.bat" -ItemType file
Set-Content "runps1.bat" `
'rem echo "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
PowerShell.exe -ExecutionPolicy Bypass -Command "& ''./%1'' %2"' ##Begin Version 1.2

####################
# web.cfg template #
####################
New-Item "web.cfg" -ItemType file
Set-Content "web.cfg" `
'%
% AeB Web Configuration file
%
\ExecuteOptions{dvips}
\bWebCustomize
% Insert redefinitions between these two marks
\eWebCustomize'

################
# cfg template #
################
New-Item "00-$class.cfg" -ItemType file
Set-Content "00-$class.cfg" '%reset the paths for \instrPath and \classPath for your system
% Use relative (*!) paths here for instructor according to dir, where tex file is located
\classPath{/#class}
\instrPath*{#instrName/backup}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Syntax:
% \classMember{firstname}{lastname}{rel-path}
% \classMember{firstname}{lastname}*{full-path}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'

# replace markers with content of vars
$pattern = "\\"
$classPath = $classPath -replace $pattern, "/"
(Get-Content "00-$class.cfg") | ForEach-Object {
    $_ -Replace '#instrName', $instrName `
      -Replace '#class', $classPath `
      -Replace ':', '' } | Set-Content "00-$class.cfg" -encoding UTF8
cd ..