summaryrefslogtreecommitdiff
path: root/support/zblbuild/zblbuild
blob: e45b23dba00a9db3dfec34345994f0f7b9c931b5 (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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
#!/bin/bash
# ZBLBUILD
# version 0.1c
# guido.milanese@unicatt.it
# 2019.08.26
#
# This interactive script helps in the setting of Biblatex options
#
# Copyright (c) 2019 Guido Milanese
# License:
# The LaTeX Project Public License License (LPPL)
# version 1.3c or later
# This work may be distributed and/or modified under the
# conditions of the LaTeX Project Public License, either version 1.3
# of this license or (at your option) any later version.
# The latest version of this license is in
#   http://www.latex-project.org/lppl.txt
# and version 1.3 or later is part of all distributions of LaTeX
# version 2005/12/01 or later.
#
# This work has the LPPL maintenance status `maintained'.
# 
# The Current Maintainer of this work is Guido Milanese.
#
# This work consists of the file zblbuild-select
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

################
# FUNCTIONS
################
#
# GENERAL:
# Function to build a radiolist and save the choice
doselect () {
mychoice=$(zenity --width=500 --height=500 \
		  --list --text "${message[@]}"\
		  --radiolist --column "Choice" --column "Name" --column "Comment-example"\
		  "${myarr[@]}")
		  retsel=$?
}

# Checks the value returned by previous function.
# if no choice calls again 'doselect'
rundoselect () {
while [ -z "$mychoice" ]; do 
			  if ((retsel != 0)); then
    zenity --error \
    --text="Cancelled -- Exiting"
    exit 1
          fi
			  doselect 
	done
}

# resets all the global values 
resetall () {
	message= ; myarr= ; mychoice=
	return ;
}

################
# CHECKDEP
################
# zenity installed?
checkdep () {
 if ! type zenity > /dev/null 2>&1; then
        echo "zenity is not installed. Exiting."; exit 1;
 fi		  
}

################
# OPENPROGRAMME
################
openprogramme () {
 zenity --info --width="500" --height="50" --no-wrap --timeout 10 --title="ZBL-BUILD" \
		--text "\n\n\n\t\t\t<big><b><span
color=\"blue\">ZBL-BUILD</span></b></big>
\t\t<span color=\"blue\"><b>Zenity Biblatex Build</b></span>\n
Sets basic BIBLATEX options,
with some options for the BIBLATEX-PHILOSOPHY styles\n
version 0.1c, 2019.08.26\n
<i>(c) 2019 Guido Milanese -- guido.milanese@unicatt.it</i>\n
\t\tLicense: LPPL\n
Warning: This utility sets a limited number of options:
please refer to the <i><b>Biblatex</b></i> manual (3.12, 10.30.2018),
and to the <i><b>Biblatex-Philosophy</b></i> manual (1.9.8a, 03.03.2018)"
}

################
# CHOOSEFILE
################
choosefile () { #
		  Fileyn= 		# resets 
		  Leaveyn=1		# the user does NOT want to leave the function
		  Bibfile=
		  Bibfile=`zenity --file-selection  --filename="/home/$USER"  --title="Select a BibTeX file"`
case $? in
         0)
                zenity --question --title="Select a BibTeX file" \
         --text="Would you like to add another file?" 
					 Fileyn=$? ;;
         1)
		zenity --question --title="Leaving?"\
                --text="No file selected!\nWould you like to leave?" 
			 Leaveyn=$? 
			 Fileyn=0
		 ;;
        -1)		 zenity --error \
			--text="Unexpected error"
                Fileyn=$? ;;
esac
# Gesamtbibfile is the complete list of files
# If Bibfile is empty does not do anything
# in order to avoid getting \addbibresource{}
# if Bibfile is not empty:
#  (1) Biblayex
#		(1) adds "\addbibresource{" ...'}' to $Bibfile
#		(2) adds $Bibfile to Gesamtbibfile with "\n"
#  (2) Markdown
#		(1) changes $Bibfile to: "-\t" $Bibfile "\n"
#		(2) adds $Bibfile to Gesamtbibfile -- no "\n"

	if [ ! -z "$Bibfile" ] ; then
#		then Bibfile="\\\\addbibresource{$Bibfile}" ; 
if [ $Bibmkd = "LaTeX" ]; then		  
	 Bibfile="\\\\addbibresource{$Bibfile}" ;
	 else Bibfile="-\t $Bibfile\n"
	 fi
if [ $Bibmkd = "LaTeX" ]; then		  
		Gesamtbibfile="$Gesamtbibfile\n$Bibfile"
		else
		Gesamtbibfile="$Gesamtbibfile$Bibfile"
fi		

	fi

if [ $Leaveyn = 0 ];	# ----------------
   then return 1		# leaves if chosen
	fi						# ----------------

if [ $Fileyn = 0 ];	# --------------
   then choosefile 	# loops if chosen
  fi						# --------------
}

################
# DOCHOOSEFILE
################
# simple wrap for choosefile:
# in this way the message is displayed only the first time
# and also adds a comment string before Gesamtbibfile (see choosefile)
# if the variable is not empty
dochoosefile () {
zenity --info --no-wrap --title "BibTeX files" \
--text "In the next window you can choose \
one or more <b>BibTeX</b> files."
choosefile
	if [ ! -z "$Gesamtbibfile" ]; then
				  if [ $Bibmkd = "LaTeX" ];
				  then Gesamtbibfile="%\n%BibTeX-file(s)$Gesamtbibfile";
				  else Gesamtbibfile=$Gesamtbibfile
				  fi
	fi
}

################
# FINALMESSAGE
################
# final msg before showing Biblatex configuration
finalmessage () {
zenity --info --no-wrap --title "Done!" \
--text "In the next window you can edit your <b>Biblatex</b> configuration \
(e.g. add options, correct your choices...) \n\
and copy/paste to your LaTeX file or YAML block. \n\
If you prefer, open and edit 'biblatex.opt' \
(in your home folder) with any text editor"
}

################
# BYEBYE
################
byebye () {
zenity --info --timeout="7" --title="Byebye" \
--text="\n\nThank you for using <b>ZBL-BUILD</b>!"
}
################
# Csquotes
################
csquotes () {
message="$Premsg 1a. Set a language for csquotes: $Pstmsg"
declare -a myarr=(\
	True  "autostyle=once" "Uses the document main language"\	  
	False "autostyle=true" "Adapts to current language"\	  
	False "austrian=quotes" " "\
	False "austrian=guillemets" " "\
	False "croatian=quotes" " "\
	False "croatian=guillemets" " "\
	False "croatian=guillemets*" " "\
	False "danish=quotes" " "\
	False "danish=guillemets" " "\
	False "danish=topquotes" " "\
	False "english=american" " "\
	False "english=british" " "\
	False "french=quotes" " "\
	False "french=quotes*" " "\
	False "french=guillemets" " "\
	False "french=guillemets*" " "\
	False "german=quotes" " "\
	False "german=guillemets" " "\
	False "german=swiss" " "\
	False "italian=guillemets" " "\
	False "italian=quotes" " "\
	False "norwegian=guillemets" " "\
	False "norwegian=quotes" " "\
	False "portuguese=portuguese" " "\
	False "portuguese=brazilian" " "\
	False "spanish=spanish" " "\
	False "spanish=mexican" " "\
	False "swedish=quotes" " "\
	False "swedish=guillemets" " "\
	False "swedish=guillemets*" " "\
		  		  );
	rundoselect
	Csquotes="\usepackage[$mychoice]{csquotes}\n"
	resetall
}

################
# Backend
################
backend () {
message="$Premsg 1b. Select backend: $Pstmsg"
declare -a myarr=(\
		  True  "biber" "Default backend of Biblatex"\
		  False "bibtex" "Legacy BibTeX -- Ascii"\
		  False "bibtex8" "BibTeX -- Latin1"\
		  );
	rundoselect
	Backend=$mychoice
	resetall
	}

#################
# Style - general
#################
setbasicstyle () {
 message="$Premsg 2. Basic style family: $Pstmsg"
 declare -a myarr=(\
		  False "authordate" "Smith 2003"\
		  False "authortitle" "Smith, The Book"\
		  False "numeric" "[1]"\
		  False "philosophy" "Humanities-oriented: several flavours"\
		  False "reading" "It simply loads the authortitle style"\
		  False "verbose" "J. Smith, The Book, Oxford 2003"\
		  False "debug" "Prints the entry key. For debugging only"\
		  False "draft" "Uses the entry keys in citations"\
		  );
	rundoselect
	Basicstyle=$mychoice
	echo $Basicstyle
	resetall
	}
######################
# Style - final choice
######################
setfinalstyle () {
 message="$Premsg 3. Given your previous choice, select a style family $Pstmsg"

        if [ $Basicstyle = 'numeric' ];
        then
           declare -a myarr=(\
			  		False "numeric" "[8, 3, 1, 7, 2]"\
			  		False "numeric-comp" "[1–3, 7, 8]"\
			  		False "numeric-verb" "[8]; [3]; [1]; [7]; [2]"\
			  		False "alphabetic" "[Doe92; Doe95; Jon98]"\
			  		False "alphabetic-verb" "[Doe92]; [Doe95]; [Jon98]"\
					); 

        elif [ $Basicstyle = 'authordate' ];
        then
           declare -a myarr=(\
		False "authoryear" "Doe 1995a; Doe 1995b; Jones 1998"\	 
		False "authoryear-comp" "Doe 1995a,b; Jones 1998"\	 
		False "authoryear-ibid" "Replaces repeated citations by 'ibidem'"\	 
		False "authoryear-icomp" "Combines authoryear-comp + authoryear-ibid"\	 
				  );
        
    elif [ $Basicstyle = 'authortitle' ];
        then
           declare -a myarr=(\
		False "authortitle" "Doe, First title; Doe, Second title"\	 
		False "authortitle-comp" "Doe, First title, Second title"\	 
		False "authortitle-dw" "Doe: First title; Second title"\	 
		False "authortitle-ibid" "Replaces repeated citations by 'ibidem'"\	 
		False "authortitle-icomp" "Combines authortitle-comp + authortitle-ibid"\	 
		False "authortitle-terse" "Prints title only if >1 titles of same author"\	 
		False "authortitle-tcomp" "Combines authortitle-comp + authortitle-terse"\	 
		False "authortitle-ticomp" "Combines authortitle-icomp +	authortitle-terse"\
				  );

        elif [ $Basicstyle = 'philosophy' ];
        then
           declare -a myarr=(\
	   False "philosophy-classic" "Knuth (1984, 1986a,b,c,d)"\	 
		False "philosophy-modern" "Citations as classic, bibliography in blocks"\	 
	   False "philosophy-verbose" "1st citation full, then short form"\ ); 

        elif [ $Basicstyle = 'verbose' ];
        then
           declare -a myarr=(\
		False "verbose" "Doe 1995a; Doe 1995b; Jones 1998"\	 
		False "verbose-ibid" "Replaces repeated citations by 'ibidem'"\	 
		False "verbose-note" "Doe 1995a,b; Jones 1998"\	 
		False "verbose-inote" "Combines authoryear-comp + authoryear-ibid"\	 
		False "verbose-trad1" "Doe, First title; Doe, Second title"\	 
		False "verbose-trad2" "Doe, First title, Second title"\	 
		False "verbose-trad3" "Replaces repeated citations by 'ibidem'"\	 
				  ); 
        elif [ $Basicstyle = 'reading' ];
        then
           declare -a myarr=(\
		True "reading" "It simply loads the authortitle style"\	 
				  ); 

     elif [ $Basicstyle = 'draft' ];
        then
           declare -a myarr=(\
		True "draft" "Uses the entry keys in citations"\	 
				  ); 

     elif [ $Basicstyle = 'debug' ];
        then
           declare -a myarr=(\
		True "debug" "Prints the entry key. For debugging only"\	 
				  ); 
		  fi		 
	rundoselect
	Style=$mychoice
	resetall	
	}

################	
# Sorting order
################
setsorting () {
 message="$Premsg 4. Sorting order. $Pstmsg"

		  declare -a myarr=(\
		  True  "nty"   "Sort by name, title, year (default)"\
		  False "nyt"   "Sort by name, year, title"\
		  False "nyvt"  "Sort by name, year, volume, title"\
		  False "anyt"  "Sort by alphabetic label, name, year, title"\
		  False "anyvt" "Sort by alphabetic label, name, year, volume, title"\
		  False "ynt"   "Sort by year, name, title"\
		  False "ydnt"  "Sort by year (descending), name, title"\
		  False "none"  "No sort. Entries processed in citation order"\
		  False "debug" "Sort by entry key. For debugging only"\
		  );
	rundoselect
	Sorting=$mychoice
	resetall
}

#####################
# General options?
#####################
generaloptyn () {
		  zenity --question --title="Additional options (general)" \
--text="Would you like to set some additional options?"
 proceed=$?		# most recent variable, i.e. return of zenity dialogue
		if ! [ $proceed = '0' ] ; 
	then styleoptyn ; setbibmd; dochoosefile ; printall ; byebye ; exit 0 ; # prints basic conf. & exits 0
			else generaloptset ; # setbibmd
		fi
		proceed=
}

#####################
# Style options?
#####################
styleoptyn () {
zenity --question  --title="Additional options for style $Basicstyle" \
--text="Would you like to set some options for <b><i>$Basicstyle</i></b>?"
 proceed=$?		# most recent variable, i.e. return of zenity dialogue
		if ! [ $proceed = '0' ] ; 
 then  dochoosefile ; finalmessage ; printall ; byebye ; exit 0 ; # prints & exits 0
 else  styleoptset  ; dochoosefile ; finalmessage ; printall ; byebye ; exit 0;	  
		fi
		proceed=
}

##########################################################
# VARIOUS TASKS
##########################################################

#####################
# GENERALOPTSET
#####################
# ADDITIONAL BIBLATEX COMMON OPTIONS:
# sets isbn, url, doi, eprint
generaloptset () {
# sets a variable from zenity using command substitution
S=`zenity --list --checklist --width=200 --height=200 --title="Choose the fields you wish to print" --column "Print?" --column "Fields" --separator=' ' \
    FALSE Isbn \
    FALSE Url \
    FALSE DOI \
    FALSE Eprint`
#####
# sets an array from variable
read -a addopt <<<$S
# scans the array and sets variables
for i in "${addopt[@]}"
do
		  case    $i in
			  Isbn)
								ISBNYN=true
								;;
	   	  Url)
					  			URLYN=true		  
								;;
           DOI)
								DOIYN=true
								;;			
		     Eprint)
								EPRINTYN=true
								;;			
esac
done
# if the variables are not set, setf them to FALSE
	if [ -z "$ISBNYN" ];   then ISBNYN=false; fi
	if [ -z "$URLYN" ];    then URLYN=false; fi
	if [ -z "$DOIYN" ];    then DOIYN=false; fi
	if [ -z "$EPRINTYN" ]; then EPRINTYN=false; fi

# builds a variable containing choices.
# if this function was not called BLCOMMON is empty & not printed
# (A) Biblatex (B) markdown
#
if [ $Bibmkd = "LaTeX" ]; then		  
		  BLCOMMON="%Options:common\n"
        BLCOMMON+="\tisbn=$ISBNYN,\n"
        BLCOMMON+="\turl=$URLYN,\n"
        BLCOMMON+="\tdoi=$DOIYN,\n"
        BLCOMMON+="\teprint=$EPRINTYN,\n"
else 		  
        BLCOMMON+="isbn=$ISBNYN,"
        BLCOMMON+="url=$URLYN,"
        BLCOMMON+="doi=$DOIYN,"
        BLCOMMON+="eprint=$EPRINTYN"
fi		  
}

#####################
# PHILSPEC
#####################
# sets options for "philosophy" flavours
# structure: if classic elif modern elif verbose
philspec () { # matches line 615
			 echo $Style
# 'if': matches the end of function
	if		
# classic 
  [ $Style = "philosophy-classic" ] 
	then
# PHSO = philosophy style options
# --------- CLASSIC -------------------
PHSO=`zenity --list --checklist --width=500 --height=225 \
--title="Classic style: see manual, p. 5" \
--text="<b>Options for philosophy-classic</b>" \
--column "True/false" --column "Fields" --column "Comment" --separator=' ' \
FALSE "square" "[] and not () in cit. and in author-year label of bibl."\
FALSE "nodate"  "Prints «nodate» when year or date is missing"`
#####
# sets an array from variable
read -a sphilopt <<<$PHSO
# scans the array and sets variables
for i in "${sphilopt[@]}"
do
		  case    $i in
			  square)
								SQUAREYN=true
								;;
	   	  nodate)
					  			NODATEYN=true		  
								;;
esac
done
# if the variables are not set, sets them to FALSE
	if [ -z "$SQUAREYN" ];    then SQUAREYN=false; fi
	if [ -z "$NODATEYN" ];    then NODATEYN=false; fi
# builds a variable containing choices.
# if this function was not called PHSPEC is empty & not printed
# for LaTeX preamble
	if [ $Bibmkd = "LaTeX" ]; then		  
		  PHSPEC="%Options:philosophy-classic\n"
        PHSPEC+="\tsquare=$SQUAREYN,\n"
        PHSPEC+="\tnodate=$NODATEYN,"
	else
# for YAML Markdown block			  
		  PHSPEC="\n"
        PHSPEC+="\tsquare=$SQUAREYN,"
        PHSPEC+="nodate=$NODATEYN,"
	fi		  
# end of CLASSIC style
#
# --------- MODERN -------------------
elif [ $Style = "philosophy-modern" ] ;
	then
# PHSO = philosophy style options
PHSO=`zenity --list --checklist --width=500 --height=225 \
--title="Philosophy-modern style: see manual, p. 5" \
--text="<b>Options for philosophy-modern</b>" \
--column "True/false" --column "Fields" --column "Comment" --separator=' ' \
FALSE "square" "[] and not () in cit. and in author-year label of bibl." \
TRUE "nodate"  "Prints «nodate» when year or date is missing" \
FALSE "yearleft"  "Prints date flushed left in bibliography" \
TRUE "restoreclassic"  "Restores 'classic style': see manual, p. 17"`
#####
# sets an array from variable
read -a sphilopt <<<$PHSO
# scans the array and sets variables
for i in "${sphilopt[@]}"
do
		  case    $i in
			  square)
								SQUAREYN=true
								;;
	   	  nodate)
					  			NODATEYN=true		  
								;;
           yearleft)
								YEARLEFTYN=true
								;;			
           restoreclassic)
	RESTORECLASSICYN="true\n%-->use:'\printbibliography[restoreclassic]'"
								;;			
esac
done
# if the variables are not set, sets them to FALSE
	if [ -z "$SQUAREYN" ];    		 then SQUAREYN=false; fi
	if [ -z "$NODATEYN" ];    		 then NODATEYN=false; fi
	if [ -z "$YEARLEFTYN" ];  		 then YEARLEFTYN=false; fi
	if [ -z "$RESTORECLASSICYN" ]; then RESTORECLASSICYN=false; fi
# builds a variable containing choices.
# if this function was not called PHSPEC is empty & not printed
# for LaTeX preamble
	if [ $Bibmkd = "LaTeX" ]; then		  
		  PHSPEC="%Options:philosophy-modern\n"
        PHSPEC+="\tsquare=$SQUAREYN,\n"
        PHSPEC+="\tnodate=$NODATEYN,\n"
        PHSPEC+="\tyearleft=$YEARLEFTYN,\n"
        PHSPEC+="\t%restoreclassic=$RESTORECLASSICYN,\n"
# for YAML markdown block
	else
		  PHSPEC="\n"
        PHSPEC+="\tsquare=$SQUAREYN,"
        PHSPEC+="nodate=$NODATEYN,"
        PHSPEC+="yearleft=$YEARLEFTYN,"
#       PHSPEC+="restoreclassic=$RESTORECLASSICYN,\n"
   fi	  
# end of MODERN style	
#
# --------- VERBOSE -------------------
  elif	[ $Style = "philosophy-verbose" ];
  then
# PHSO = philosophy style options 
PHSO=`zenity --list --checklist --width=500 --height=225 \
--title="Verbose style: see manual, p. 6" \
--text="<b>Options for philosophy-verbose</b>" \
--column "True/false" --column "Fields" --column "Comment" --separator=' '\
   FALSE "latinemph" "Prints «ibid.» italicised"\
   FALSE  "commacit"  "Adds comma after shorttitle if follwed by «cit.»"`
		
#####
# sets an array from variable
read -a sphilopt <<<$PHSO
# scans the array and sets variables
for i in "${sphilopt[@]}"
do
		  case    $i in
			  latinemph)
								LATINEMPHYN=true
								;;
	   	  commacit)
					  			COMMACITYN=true		  
								;;
esac
done
# if the variables are not set, setf them to FALSE
	if [ -z "$LATINEMPHYN" ]; then LATINEMPHYN=false; fi
	if [ -z "$COMMACITYN" ];  then COMMACITYN=false; fi

# builds a variable containing choices.
# if this function was not called BLCOMMON is empty & not printed
# for LaTeX preamble
	if [ $Bibmkd = "LaTeX" ]; then		  
		  PHSPEC="%Options:philosophy-verbose\n"
        PHSPEC+="\tlatinemph=$LATINEMPHYN,\n"
        PHSPEC+="\tcommacit=$COMMACITYN\n"
# for YAML markdown block		  
   else
		  PHSPEC="\n"
        PHSPEC+="\tlatinemph=$LATINEMPHYN,"
        PHSPEC+="commacit=$COMMACITYN,"
	fi		  
fi # end of PHISPEC
}  # matches the beginning of function: 475

###############
# STYLEOPTSET
###############
# sets options style by style
# --> todo -- works only for philosophy!
styleoptset () {
		  if [ $Basicstyle = "philosophy" ];
        then
zenity --info --no-wrap --title="Style «$Basicstyle» options" --text=\
"The following windows help setting the common options \n\
of style <b>«$Basicstyle»</b>.\n\
For advanced options please refer to manuals."
# (a) options for basic style philosophy -- 1. true/false
# PHCA = Philosophy Common Options (A)
# FALSE "scauthors" "Author, editor etc. in small caps (cite/biblio)" \
# the above option deleted -- does not work any more? 2019.08.25		  
PHCA=`zenity --list --checklist --width=600 --height=300 --title="Global options
for «philosophy»: see manual, pp. 14-17" --column "True/false" --column "Options" --column "Comment" --separator=' ' \
FALSE "shorthandintro" "Language-specific expression e.g. «hence-forth cited as»" \
FALSE "scauthorsbib" "Author, editor etc. in small caps (biblio only)" \
FALSE "scauthorscite" "Author, editor etc. in small caps (cite only)" \
FALSE "lowscauthors" "Author, editor etc. in lowercase small caps" \
FALSE "inbeforejournal" "Prints 'in' before journaltitle (@article)" \
FALSE "annotation" "Prints annotation field in bibliography" \
FALSE "library" "Prints library field in citations and bib."`
#####

# sets an array from variable PHCA
read -a phopt <<<$PHCA
# scans the array and sets variables
for i in "${phopt[@]}"
do
		  case    $i in
			  shorthandintro)
								SHORTHANDINTROYN=true
								;;
#	   	  scauthors)
#					  			SCAUTHORSYN=true -- removed, see above: 2019.08.25
#								;;
	   	  scauthorsbib)
					  			SCAUTHORSBIBYN=true		  
								;;
	   	  scauthorscite)
					  			SCAUTHORSCITEYN=true		  
								;;
	   	  lowscauthors)
					  			LOWSCAUTHORSYN=true		  
								;;
	   	  inbeforejournal)
					  			INBEFOREJOURNALYN=true		  
								;;
	   	  annotation)
					  			ANNOTATIONYN=true		  
								;;
	   	  library)
					  			LIBRARYYN=true		  
								;;
esac
done
# if the variables are not set, setf them to FALSE
	if [ -z "$SHORTHANDINTROYN" ];   then SHORTHANDINTROYN=false; fi
#	if [ -z "$SCAUTHORSYN" ];        then SCAUTHORSYN=false; fi -- removed 2019.08.25 
	if [ -z "$SCAUTHORSBIBYN" ];     then SCAUTHORSBIBYN=false; fi
	if [ -z "$SCAUTHORSCITEYN" ];    then SCAUTHORSCITEYN=false; fi
	if [ -z "$LOWSCAUTHORSYN" ];     then LOWSCAUTHORSYN=false; fi
	if [ -z "$INBEFOREJOURNALYN" ];  then INBEFOREJOURNALYN=false; fi
	if [ -z "$ANNOTATIONYN" ];       then ANNOTATIONYN=false; fi
	if [ -z "$LIBRARYYN" ];          then LIBRARYYN=false; fi

# (b) options for basic style philosophy -- 2. choices
message="$Premsg Choose relatedformat (manual, p. 21): $Pstmsg"
declare -a myarr=(\
		  True  "semicolon" "The “related” entry is preceded by a semicolon"\
		  False "parens" "Puts the “related” entry in parentheses"\
		  False "brackets" "Same as the previous option but with brackets"
		  );
	rundoselect
	Relatedformat=$mychoice
	resetall
	
message="$Premsg Choose publocformat (manual, p. 14): $Pstmsg"
declare -a myarr=(\
		  True  "publocyear" "Oxford University Press, Oxford 2007"\
		  False "locpubyear" "Oxford, Oxford University Press, 2007"\
		  False "loccolonpub" "Oxford: Oxford University Press, 2007"
		  );
	rundoselect
	Publocformat=$mychoice
	resetall

message="$Premsg Choose volnumformat (manual, p. 15): $Pstmsg"
declare -a myarr=(\
		  True  "plain"   "Journal Title, 5, 8"\
		  False "strings" "Journal Title, vol. 5, n. 8"\
		  False "parens"  "Journal Title (5, 8)"
		  );
	rundoselect
	Volnumformat=$mychoice
	resetall
	
message="$Premsg Choose volumeformat (manual, p. 15): $Pstmsg"
declare -a myarr=(\
		  True  "arabic"  "Book Title, vol. 12"\
		  False "roman"   "Book Title, vol. xii (lowercase)"\
		  False "romansc" "Book Title, vol. xıı (small caps)"\
		  False "Roman"   "Book Title, vol. XII (uppercase)"
		  );
	rundoselect
	Volumeformat=$mychoice
	resetall

message="$Premsg Choose editionformat (manual, p. 15): $Pstmsg"
declare -a myarr=(\
		  True  "arabic"  "Book Title, 3ª ed."\
		  False "roman"   "Book Title, iii ed. (lowercase)"\
		  False "romansc" "Book Title, ııı ed. (small caps)"\
		  False "Roman"   "Book Title, III ed. (uppercase)"\
		  False "superscript"   "Book Title, 2010³ (verbose only)"
		  );
	rundoselect
	Editionformat=$mychoice
	resetall
	philspec
# builds a variable containing true/false and choices.
# if this function was not called PHCOMMON is empty & not printed
# If Biblatex
if [ $Bibmkd = "LaTeX" ]; then
	PHCOMMON="%Options:philosophy-common\n"
# common 'philosophy' true/false	
	PHCOMMON+="\tshorthandintro=$SHORTHANDINTROYN,\n"
#	PHCOMMON+="\tscauthors=$SCAUTHORSYN,\n"
	PHCOMMON+="\tscauthorsbib=$SCAUTHORSBIBYN,\n"
	PHCOMMON+="\tscauthorscite=$SCAUTHORSCITEYN,\n"
	PHCOMMON+="\tlowscauthors=$LOWSCAUTHORSYN,\n"
	PHCOMMON+="\tinbeforejournal=$INBEFOREJOURNALYN,\n"
	PHCOMMON+="\tannotation=$ANNOTATIONYN,\n"
	PHCOMMON+="\tlibrary=$LIBRARYYN,\n"
# common 'philosophy' choices	
	PHCOMMON+="\trelatedformat=$Relatedformat,\n"
	PHCOMMON+="\tpublocformat=$Publocformat,\n"
	PHCOMMON+="\tvolnumformat=$Volnumformat,\n"
	PHCOMMON+="\tvolumeformat=$Volumeformat,\n"
	PHCOMMON+="\teditionformat=$Editionformat,\n"
	else
# if Markdown YAML
# NB: \n\t important: if the field is left empty
# no spurious \n\t will be written to the YAML block
	PHCOMMON="\n\t"
	PHCOMMON+="shorthandintro=$SHORTHANDINTROYN,"
#	PHCOMMON+="scauthors=$SCAUTHORSYN,"
	PHCOMMON+="scauthorsbib=$SCAUTHORSBIBYN,"
	PHCOMMON+="scauthorscite=$SCAUTHORSCITEYN,"
	PHCOMMON+="lowscauthors=$LOWSCAUTHORSYN,"
	PHCOMMON+="inbeforejournal=$INBEFOREJOURNALYN,"
	PHCOMMON+="annotation=$ANNOTATIONYN,"
	PHCOMMON+="library=$LIBRARYYN,"
# common 'philosophy' choices	
	PHCOMMON+="relatedformat=$Relatedformat,"
	PHCOMMON+="publocformat=$Publocformat,"
	PHCOMMON+="volnumformat=$Volnumformat,"
	PHCOMMON+="volumeformat=$Volumeformat,"
	PHCOMMON+="editionformat=$Editionformat,"
	fi
# end of philosophy -- default does not do anything but print a message
	else
zenity --info --width="250" --no-wrap --title "More soon!" --text \
"\n<span color=\"blue\"><b>Additional options for style\
\n\t\t«$Basicstyle»\n\
will be available in version 0.2</b></span>"
#   finalmessage 		  -- canc
	 fi # refer to function beginning to nest IF-S!
}

#############
# SETBIBMD
#############
setbibmd () {
 message="$Premsg 1. LaTeX or Markdown? $Pstmsg"
		  declare -a myarr=(\
		  False "LaTeX"    "LaTeX preamble"\
		  False "Markdown" "Markdown YAML block"\
		  );
	rundoselect
	Bibmkd=$mychoice
	resetall
}

###############
# PRINTALL
###############
# prepares a long variable & prints to a file
# if (1) = Biblatex (2) = markdown
printall () {
# if LaTeX		  
if [ $Bibmkd = "LaTeX" ]; then		  
		  BLOPT="$Csquotes"
        BLOPT+="\\usepackage\n"
        BLOPT+="\t[%\n"
        BLOPT+="\tbackend=$Backend,\n"
        BLOPT+="\tstyle=$Style,\n"
        BLOPT+="\tsorting=$Sorting,\n"
		  BLOPT+="$BLCOMMON"
		  BLOPT+="$PHCOMMON"
		  BLOPT+="$PHSPEC"
        BLOPT+="\t]%\n"
        BLOPT+="{biblatex}\n"
        BLOPT+="$Gesamtbibfile\n"
# if YAML Markdown block
else
		  BLOPT="citation_package:\t biblatex\n"
		  BLOPT+="biblio-style:\t $Style,backend=$Backend,\n"
		  BLOPT+="biblatexoptions:\t |\n\t
		  sorting=$Sorting,$BLCOMMON,$PHCOMMON,$PHSPEC"
#		  BLOPT+="$BLCOMMON,$PHCOMMON,$PHSPEC\n"
		  BLOPT+="\nbibliography:\n $Gesamtbibfile\n"
#		  BLOPT="${BLOPT//,,/,}" # change double comma to single -- USELESS
#		  BLOPT="${BLOPT//'\n\n'/'\n'}" # change double \n to single -- USELESS
fi		  
			
        printf %b $BLOPT >biblatex.opt 
# now the file is read by zenity		  
  zenity  --width="550" --height="600" --text-info --timeout 20 \
--title="Editable biblatex configuration" --editable \
			 --font=mono \
			 --filename=biblatex.opt
}

# Sets formatting codes for window titles
Premsg="<big><b>"
Pstmsg="</b></big>"

################
# Main
################
	checkdep					# check dependencies
	openprogramme			# info, version
	setbibmd					# sets Biblatex or MD
	csquotes					# sets csquotes options
 	backend					# sets backend
	setbasicstyle			# sets basic style
	setfinalstyle			# sets final style
	setsorting				# sets sorting order
	generaloptyn			# additional general options y/n
	styleoptyn				# additional style options y/n

################
# History
################
#								*	0.1c
#								*	Biblio PATH was hardcoded: bug, corrected
#  2019.08.16				*	0.1b
#								*  added author-title in general choice
#								*	Ref. to philosophy manual updated
#	2015.10.16				*	0.1a
#								*	Added editionformat=superscript (philosophy-verbose)
#								*	Minor improvements (e.g. English wording)
#								*	New license: LPPL
#	2015.08.25				First complete version (0.1)
#	2015.08.24				Beta version
#	2015.08.23				Alfa version
#	2015.08.20				First draft

################
# TODO
################
#	Options for more styles
#	Uniform windows sizes or not?

################
# BUGS
################
#	printf complains about missing unicode digit for \u
#		but see e.g.