encoding  utf-8

# Licence
#
#<en> Released under a Creative Commons Attribution-ShareAlike-NonCommercial License:
#<fr> Publié sous la licence Creative Commons Attribution-ShareAlike-NonCommercial:
#     <http://creativecommons.org/licenses/by-nc-sa/4.0/>
#
# Written by: / Ecrit par : Xavier Robert
#

#<en> File to set up specific settings for Therion drawing outputs
#     In your *.thconfig file, you need to call this file with:
#<fr> Fichier pour définir une configuration pour les dessins de issus de Therion
#     Dans votre fichier *.thconfig, vous devez appeller ce fichier avec la ligne :
#         input <path/to/the/file/>config.thc
#<en> and then, in each layout, you need to call the corresponding layout:
#<fr> et ensuite, dans chaque layout de votre thconfig, vous devez appeler les layouts qui vous intéressent comme par exemple :
#         copy drawingconfig
#
#<en> Lots of definition comes from (or are deeply inspired by) the excellent Therion Wiki
#<fr> Beaucoup de définitions proviennent (ou sont fortement inspirées) de l'excellent Wiki Therion
#         https://therion.speleo.sk/wiki/doku.php

# Existing user points / nouvelles définitions de points :
#	- nid/nest (u:nest)
#	- gradient -->	geologic dip
#	- danger (u:danger)
#	- chauves-souris/bats (u:bats)
#	- stalactite boss (u:boss)
#	- Shell/coquille fossile (u:shell)
#	- Masonry/maçonnerie (u:masonry)
#	- Ex voto/Signature (u:ex_voto)
#	- Human bones/Ossements humains (u:human_bones)
#	- Walking Caver/Spéléo qui marche (u:man_w)
# 	- Climbing caver/Spéléo qui grimpe (u:man_c)
#	- Plan view symbol/symbole de vue en plan (u:symbol_plan)
#	- extended view symbol/symbole de vue en coupe développée (u:symbol_extend)

# Existing user lines:
#	- strate/strata (u:strata; option -clip off)
#	- coupole (u:coupole; option -clip off)
#	- faille/fault (u:fault; option -clip off)
#	- doline (u:doline; option -clip off)
#	- chauves-souris/bats (u:bats)
#	- rail (u:rail)
#	- plan walk/ (u:planwalk)
#	- handrail/rambarde (u:handrail)
#	- Surface (u:surf)
#	- Dive line/fil d'Ariane (u:ariane)
#	- Deviation (u:deviation)

# Existing user areas:
# 	- boue/mud (u:boue)
#	- guano (u:guano)
#	- chauves-souris/bats (u:bats)
#	- tronc/tree-trunk (u:tronc)
#	- feuilles/tree-leaves (u:feuilles)
#	- Tunnel initiation/Départ de galerie (u:galerie)


#<en> change the names for the legend
#<fr> change les descriptions des symboles pour la légende
text en "line u:rope" "rope" #text to appear in legend
text fr "line u:rope" "corde" #text to appear in legend
text es "line u:rope" "cuerda" #text to appear in legend

text en "line u:fault" "fault" #text to appear in legend
text fr "line u:fault" "faille" #text to appear in legend
text es "line u:fault" "falla" #text to appear in legend

text en "line u:strata" "strata" #text to appear in legend
text fr "line u:strata" "strate" #text to appear in legend
text es "line u:strata" "strata" #text to appear in legend

text en "line u:doline" "doline" #text to appear in legend
text fr "line u:doline" "doline" #text to appear in legend
text es "line u:doline" "dolina" #text to appear in legend

text en "point u:bats" "bat(s)"
text fr "point u:bats" "chauve-souris"
text es "point u:bats" "murciélago(s)"

text en "line u:bats" "bat path"
text fr "line u:bats" "passage de chauve-souris"
text es "line u:bats" "ruta de murciélagos"

text en "area u:bats" "lot of bats"
text fr "area u:bats" "beaucoup de chauve-souris"
text es "area u:bats" "muchos murciélagos"

text fr "area u:galerie" "départ de galerie"
text en "area u:galerie" "tunnel departure"
text es "area u:galerie" "salida de galeria"

text en "point u:guacharos" "guacharos"
text fr "point u:guacharos" "guacharos"
text es "point u:guacharos" "guacharos"

text fr "point danger" "danger !"
text en "point danger" "danger !"
text es "point danger" "danger !"

text en "point masonry" "masonry"
text fr "point masonry" "maçonnerie/murs"
text es "point masonry" "albañilería/muros"

text en "point ex-voto" "ex voto"
text fr "point ex-voto" "ex voto/signature"
text es "point ex-voto" "ex voto/firma"

text en "point human-bones" "human bones"
text fr "point human-bones" "ossements humains"
text es "point human-bones" "huesos humanos"

text en "point u:boss" "stalagmite boss"
text fr "point u:boss" "stalagmite boss"
text es "point u:boss" "stalagmite boss"

text fr "area u:guano" "guano"
text en "area u:guano" "guano"
text es "area u:guano" "guano"

text fr "area u:boue" "lac de boue"
text en "area u:boue" "mud lake"
text es "area u:boue" "lago de barro"

text fr "area u:tronc" "tronc d'arbre"
text en "area u:tronc" "Tree trunk"
text es "area u:tronc" "tronca de árbol"

text fr "area u:feuilles" "feuilles/feuillage"
text en "area u:feuilles" "tree leaves"
text es "area u:feuilles" "Hojas de árbol"

text en "line u:sentier" "trail"
text fr "line u:sentier" "sentier"
text es "line u:sentier" "sendero"

text en "point u:shell" "shell"
text fr "point u:shell" "fossile"
text es "point u:shell" "fosíl"

# Correction texte espagnol
text es "point air-draught" "corriente de aire"
text es "line rock-border" "contorno de bloque"
#text es "point water-flow" "curso de agua"
#text es "line water-flow" "curso de agua"
##text es "group water-flow" "curso de agua"
text es "point water-flow:permanent" "riachuelo"
text es "line water-flow:permanent" "riachuelo"
text es "point water-flow:intermittent" "riachuelo intermitente"
text es "line water-flow:intermittent" "riachuelo intermitente"
text es "line water-flow:conjectural" "riachuelo supuesto"

text es "line rock-edge" "arista de bloque"
text es "point cave-pearl" "perlas de cavernas"

text es "point rimstone-dam" "travertino"
text es "point rimstone-pool" "travertino"
text es "point stalactite" "estalactita"
text es "point stalactites" "estalactitas"
text es "point stalagmite" "estalagmita"
text es "point stalagmites" "estalagmitas"
text es "point pillars" "pilares"
text es "point pillar" "pilare"

text fr "point traverse" "vire"
text fr "point ice-stalagmite" "stalagmite de glace"

text fr "point u:anchor_artificial" "Ancrage artificiel"
text fr "point u:anchor_natural" "Ancrage naturel"

text en "point u:man_w" "caver (walking)"
text fr "point u:man_w" "spéléo (marchant)"
text es "point u:man_w" "espeleológo (caminando)"

text en "point u:man_c" "caver (climbing)"
text fr "point u:man_c" "spéléo (grimpant)"
text es "point u:man_c" "espeleológo (escalando)"

text en "point u:symbol_plan" ""
text fr "point u:symbol_plan" ""
text es "point u:symbol_plan" ""

text en "point u:symbol_extend" ""
text fr "point u:symbol_extend" ""
text es "point u:symbol_extend" ""


### Layouts Languages/langues

#<en> Different layouts to manage languages (en, fr, es)
#     In your thconfig, call the layout langue-XX where XX is en, fr or es
#     You need to add one of these layout if you use the layout headerl or header_coupe
#     If you want to add one of the field club, syntesys, web page, expedition, guide, 
#        add the following line in the code tex-map/endcode block of your layout in the thconfig
#		   \newtoks\YYYY \YYYY={the value of your variable}
#        where YYYY = club, synth, wpage, expe or guide
#<fr> Différents layouts pour définir les langues (pour l'instant : en, fr, es)
#     Dans votre thconfig, appelez le layout langue-XX où XX est en, fr ou es
#     Vous devez ajouter l'un de ces layouts si vous voulez utiliser les layouts headerl ou header_coupe
#     qui redéfinissent la présentation et les informations du cartouche (header).
#     Si vous voulez ajouter un de ces champs club, syntesys, web page, expedition, guide, 
#        rajouter la ligne suivante dans le bloc code tex-map/endcode  de votre layout dans votre thconfig
#        (voir les exemples)
#		   \newtoks\YYYY \YYYY={Valeur de votre varialbe}
#        où YYYY = club, synth, wpage, expe or guide
#
#<en> You may add new fields, following the examples in the layouts. 
#     If you add a new field, you need to edit the layout(s) headerl and/or header_coupe
#<fr> Vous pouvez ajouter de nouveaux champs, en suivant les exemples dans les layouts suivant.
#     Si vous rajouter un nouveau champ, vous devrez éditer le(s) layout(s) headerl et/ou header_coupe

layout langue-fr
	# Définit la langue française
	language fr
	
	code tex-map
		% Definition of variables for the tuned headers :
		\newtoks\thversiontitleB \thversiontitleB={Therion }

		\newtoks\thversiontitleA \thversiontitleA={Compilation }
		\newtoks\datetitle \datetitle={le }
		\newtoks\thproj \thproj={Projection }
		\newtoks\thclub \thclub={Club(s) }
		\newtoks\thsynth \thsynth={Synthèse }
		\newtoks\thwpage \thwpage={Page internet }
		\newtoks\thexpe \thexpe={Expedition }
		\newtoks\thguide \thguide={Guide(s) }
		\newtoks\depthrangetitle \depthrangetitle={Depth range from }
		\newtoks\ththanksto \ththanksto{Nos remerciements }
		\newtoks\thcoords \thcoords{Coordonnées }
		
		

		# Initiate variables
		\newtoks\club \club={}
		\newtoks\synth \synth={}
		\newtoks\wpage \wpage={}
		\newtoks\expe \expe={}
		\newtoks\guide \guide={}
		\newtoks\thanksto \thanksto={}
		\newtoks\ECoordinates \ECoordinates={}
		
	endcode
endlayout


layout langue-es
	# Definición del idioma español
	language es
	
	code tex-map
		% Definition of variables for the tuned headers :
		\newtoks\thversiontitleB \thversiontitleB={Therion }

		\newtoks\thversiontitleA \thversiontitleA={Compilación}
		\newtoks\datetitle \datetitle={el }
		\newtoks\thproj \thproj={Proyección}
		\newtoks\thclub \thclub={Club(es)}
		\newtoks\thsynth \thsynth={Síntesis}
		\newtoks\thwpage \thwpage={Página web}
		\newtoks\thexpe \thexpe={Expedición}
		\newtoks\depthrangetitle \depthrangetitle={Depth range from }
		\newtoks\thguide \thguide={Guia(s)}
		\newtoks\ththanksto \ththanksto{Nuestros agradecimientos }
		\newtoks\thcoords \thcoords{Coordinadas GPS (WGS84) }
		
		\cartotitle={Dibujo}

		# Initiate variables		
		\newtoks\club \club={}
		\newtoks\synth \synth={}
		\newtoks\wpage \wpage={}
		\newtoks\expe \expe={}
		\newtoks\guide \guide={}
		\newtoks\thanksto \thanksto={}
		\newtoks\ECoordinates \ECoordinates={}
		
	endcode	
	
endlayout


layout langue-en
	# Set the language english
	language en
	
	code tex-map
		% Definition of variables for the tuned headers :
		\newtoks\thversiontitleB \thversiontitleB={Therion }
		
		\newtoks\thversiontitleA \thversiontitleA={Compiled}
		\newtoks\datetitle \datetitle={on }
		\newtoks\thproj \thproj={Projection}
		\newtoks\thclub \thclub={Club(s)}
		\newtoks\thsynth \thsynth={Synthesys}
		\newtoks\thwpage \thwpage={Web page}
		\newtoks\thexpe \thexpe={Expedition}
		\newtoks\depthrangetitle \depthrangetitle={Depth range from }
		\newtoks\thguide \thguide={Guide(s)}
		\newtoks\ththanksto \ththanksto{Acknowledgments }
		\newtoks\thcoords \thcoords{GPS coordinates (WGS84) }

		# Initiate variables
		\newtoks\club \club={}
		\newtoks\synth \synth={}
		\newtoks\wpage \wpage={}
		\newtoks\expe \expe={}
		\newtoks\guide \guide={}
		\newtoks\thanksto \thanksto={}
		\newtoks\ECoordinates \ECoordinates={}
		
	endcode	
	
endlayout

###<en> End of the layouts languages
###<fr> Fin des layouts languages
#______________________________




layout drawingconfig
#<en> Layout to draw the map and extended view.
#<fr> Layout pour dessiner les plans et les coupes développées.
	
	#<en> pdf-Author
	#<fr> Auteur du pdf
	doc-author "Xavier Robert"

	#<en> Set the symology you want to use: UIS, ASF (Australie) CCNP (Etats Units) ou
	#                                       SKB (tchecoslovakia)
	#<fr> Définit la banque de symboles que nous voulons utiliser : 
	#         UIS, ASF (Australie) CCNP (Etats Units) ou SKB (tchecoslovakia)
	#symbol-set UIS
	#<en> Change the type or colors of specific symbols:
	#<fr> Changer le type ou la couleur de symboles spécifiques:	
	symbol-assign point station:temporary SKBB
	symbol-assign point pillar AUT
	
	symbol-color point water-flow [17 46 100]
	symbol-color point water-flow:intermittent [17 46 100]
	symbol-color point water-flow:paleo [17 46 100]
	symbol-color point water-drip [17 46 100]
	symbol-color point water [17 46 100]
	symbol-color line water-flow [17 46 100]
	symbol-color line water-flow:conjectural [17 46 100]
	symbol-color line water-flow:intermittent [17 46 100]
	symbol-color point ice [0 0 100]
	symbol-color line wall:ice [0 0 100]
	symbol-color point ice-pillar [0 0 100]
	symbol-color point ice-stalagmite [0 0 100]
	symbol-color point ice-stalactite [0 0 100]
	symbol-color area ice [0 0 100]
	symbol-color point snow [0 0 100]
	symbol-color area snow [0 0 100]
	symbol-color point spring [17 46 100]
	symbol-color point root [52 33 6]
	symbol-color point vegetable-debris [13 47 6]
	symbol-color point seed-germination [13 47 6]
	symbol-color point altitude [100 50 0]
	symbol-color point station [54 7 60]
	symbol-color line flowstone [100 60 20]
	symbol-color line wall:flowstone [100 60 20]
	symbol-color point flowstone [100 60 20]
	symbol-color area flowstone [100 60 20]
	symbol-color area moonmilk [100 60 20]	# Change the color ?
	symbol-color point moonmilk [100 60 20]	# Change the color ?
	symbol-color line wall:moonmilk [100 60 20]	# Change the color ?
	symbol-color point curtains [100 60 20]
	symbol-color point curtain [100 60 20]
	symbol-color point disc-pillar [100 60 20]
	symbol-color point disc-stalactite [100 60 20]
	symbol-color point disc-stalagmite [100 60 20]
	symbol-color point disc-pillars [100 60 20]
	symbol-color point disc-stalactites [100 60 20]
	symbol-color point disc-stalagmites [100 60 20]
	symbol-color point disk [100 60 20]
	symbol-color point wall-calcite [100 60 20]
	symbol-color point pillar [100 60 20]
	symbol-color point pillar-with-curtains [100 60 20]
	symbol-color point pillars-with-curtains [100 60 20]
	symbol-color point stalactite [100 60 20]
	symbol-color point stalagmite [100 60 20]
	symbol-color point stalactite-stalagmite [100 60 20]
	symbol-color point stalactites-stalagmites [100 60 20]
	symbol-color point stalactites [100 60 20]
	symbol-color point stalagmites [100 60 20]
	symbol-color point flowstone-choke [100 60 20]
	symbol-color line rimstone-dam [100 60 20]
	symbol-color line rimstone-pool [100 60 20]
	symbol-color point rimstone-dam [100 60 20]
	symbol-color area stalactite [100 60 20]
	symbol-color area stalactite-stalagmite [100 60 20]
	symbol-color area stalagmite [100 60 20]
	symbol-color area pillar [100 60 20]
	symbol-color area pillar-with-curtains [100 60 20]
	symbol-color area mudcrack [52 33 6]	# Color to verify ; Maybe to darken
	symbol-color area clay [52 33 6]	# Color to verify
	symbol-color line wall:clay [52 33 6]	# Color to verify
	symbol-color point volcano [52 33 6]	# Color to verify
	symbol-color point mud [52 33 6]	# Color to verify
	symbol-color point mudcrack [52 33 6]	# Color to verify
	symbol-color point clay [52 33 6]	# Color to verify
	#symbol-color point clay-tree [52 33 6]	# Color to verify
	symbol-color point clay-choke [52 33 6]	# Color to verify
	symbol-color point wall-altitude [78 8 52]	# rouge-violet 199, 21, 133 --> normal
	#symbol-color point wall-altitude [0 0 100]	# Bleu 0, 0, 255 --> For sumps/siphons

	####### Metapost-changes ############
	code metapost

		#<en> Modify length/depth statistics to print
		#<fr> Modifier l'aspect et les données des statistiques de longueur affichées si besoin
		#code tex-map
		#	\cavelength{1330\thinspace{}m}
		#	+ 150\thinspace{}m estimes}
		#	\cavedepth{243\thinspace{}m}
		#endcode


		#<en> Change the dashed line for the line wall:presumed
		#<fr> Changer la ligne pointillée du symbole line wall:presumed
		def l_wall_presumed (expr P) = 
			T:=identity;
			pickup PenA;
			# Old definition
			#thdraw P dashed evenly scaled (2*optical_zoom);
			# New definition
			thdraw P dashed evenly scaled (.1u);
		enddef;
		
		#<en> Change the dashed line for the line chimney
		#<fr> Changer la ligne pointillée du symbole line chemney (cheminée)
		def l_chimney (expr P) = 
			T:=identity;
			pickup PenC;
			%thdraw P dashed evenly scaled optical_zoom;
			thdraw P dashed evenly scaled (.05u);
		enddef;

		#<en> To change blocs size in the area blocks
		#<fr> Pour modifier la taille des blocs dans l'aire blocks
		def a_blocks (expr p) =
			T:=identity;
			pickup PenC;
			path q, qq; q = bbox p;
			picture tmp_pic;
			uu := max(u, (xpart urcorner q - xpart llcorner q)/100, (ypart urcorner q - ypart     llcorner q)/100);
			tmp_pic := image(
			for i = xpart llcorner q step 1.0uu until xpart urcorner q:
				for j = ypart llcorner q step 1.0uu until ypart urcorner q:
					qq := punked (((-.3uu,-.3uu)--(.3uu,-.3uu)--(.3uu,.3uu)--(-.3uu,.3uu)--cycle)
					randomized (uu/2))
						rotated uniformdeviate(360)
						shifted ((i,j) randomized 1.0uu);
					if xpart (p intersectiontimes qq) < 0:
						thclean qq;
						thdraw qq;
					fi;
				endfor;
			endfor;
			);
			clip tmp_pic to p;
			draw tmp_pic;
		enddef;

 		#<en> To change sand aspects
 		#<fr> Pour modifier les aspects du sable dans l'aire associée
	 	def a_sands (expr p) =
			T:=identity;
			pickup PenC;
			path q; q = bbox p;
			picture tmp_pic;
			tmp_pic := image(
			for i = xpart llcorner q step 0.1u until xpart urcorner q:
				for j = ypart llcorner q step 0.1u until ypart urcorner q:
					draw origin shifted ((i,j) randomized 0.1u) withpen PenC;
				endfor;
			endfor;
			);
			#clip tmp_pic to p;
			draw tmp_pic;
		enddef;

 		#<en> To change pebbles aspects
 		#<fr> Pour modifier l'aspects de l'aire pebbles (galets)
	 	def a_pebbles_SKBB (expr p) =
			T:=identity;
			pickup PenC;
			path q, qq; q = bbox p;
			picture tmp_pic;
			tmp_pic := image(
			for i = xpart llcorner q step .1u until xpart urcorner q:
				for j = ypart llcorner q step .5u until ypart urcorner q:
					qq := (superellipse((.07u,0),(0,.03u), (-.07u,0),(0,.-.03u),.75))
					%randomized (u/25)
					rotated uniformdeviate(360)
					shifted ((i,j) randomized 0.27u);
					if xpart (p intersectiontimes qq) < 0:
						thdraw qq;
					fi;
				endfor;
			endfor;
			);
			clip tmp_pic to p;
			draw tmp_pic;
		enddef;

		#<en> To change slopes aspects
		#<fr> Pour modifier la ligne aspects
		def l_slope (expr P,S)(text Q) = 
			%show Q;
			T:=identity;
			numeric dirs[];
			numeric lengths[];
			for i=Q:
				dirs[redpart i]:=greenpart i;
				lengths[redpart i]:=bluepart i;
			endfor;  
			li:=length(P); % last
			alw_perpendicular:=true;
			for i=0 upto li:
				if unknown dirs[i]: dirs[i]:=-1; 
				else: 
					if dirs[i]>-1:
						dirs[i]:=((90-dirs[i]) - angle(thdir(P,i))) mod 360;
						alw_perpendicular:=false;
					fi;
				fi;
				if unknown lengths[i]: lengths[i]:=-1; fi;
			endfor;
			%for i=0 upto li: show dirs[i]; endfor;
			ni:=0; % next
			pi:=0; % previous
			for i=0 upto li:
				d:=dirs[i];
				if d=-1:
					if (i=0) or (i=li):
						dirs[i] := angle(thdir(P,i) rotated 90) mod 360;
						pi:=i;
					else:
						if ni<=i:
							for j=i upto li:
								ni:=j;
								exitif dirs[j]>-1;
							endfor;
						fi;
						w:=arclength(subpath(pi,i) of P) / 
						arclength(subpath(pi,ni) of P);
						dirs[i]:=w[dirs[pi],dirs[ni]];
						%if (dirs[i]-angle(thdir(P,i))) mod 360>180:
						%dirs[i]:=w[dirs[ni],dirs[pi]];
						%message("*******");
						%fi;
					fi;
				else:
					pi:=i;
				fi;
			endfor;
			%for i=0 upto li: show dirs[i]; endfor;
			ni:=0; % next
			pi:=0; % previous
			for i=0 upto li:
				l:=lengths[i];
				if l=-1:
					if (i=0) or (i=li):
						lengths[i] := 1cm; % should never happen!
						thwarning("slope width at the end point not specified");
						pi:=i;
					else:
						if ni<=i:
							for j=i+1 upto li:
								ni:=j;
								exitif lengths[j]>-1;
							endfor;  
						fi;
						w:=arclength(subpath(pi,i) of P) /   
						arclength(subpath(pi,ni) of P);
						lengths[i]:=w[lengths[pi],lengths[ni]];
						pi:=i;
					fi;
				else:
					pi:=i;
				fi;
			endfor;
			%for i=0 upto li: show lengths[i]; endfor;
			T:=identity;
			boolean par;
			cas := 0.3u;
			krok := 0.7u;
			dlzka := (arclength P);
			if dlzka>3u: dlzka:=dlzka-0.6u fi;
			mojkrok:=adjust_step(dlzka,1.4u) / 5;
			pickup PenD;
			par := false;
			forever:
				t := arctime cas of P;
				if t mod 1>0:  % not a key point
					w := (arclength(subpath(floor t,t) of P) / 
					arclength(subpath(floor t,ceiling t) of P));
					if alw_perpendicular:
						a := 90;
					else:
						a := w[dirs[floor t],dirs[ceiling t]];
					fi;
					l := w[lengths[floor t],lengths[ceiling t]];
				else:
					if alw_perpendicular:
						a := 90;
					else:
						a:= dirs[t];
					fi; 
					l:=lengths[t];
				fi;    
				a := a + angle(thdir(P,t));    
				thdraw (point t of P) -- 
				((point t of P) + if par: 0.333 * fi l * unitvector(dir(a)));
				cas := cas + mojkrok;
				par := not par;
				exitif cas > dlzka + .3u + (krok / 3);  % for rounding errors
			endfor;
			if S = 1: pickup PenC; draw P fi;
				%pickup pencircle scaled 3pt;
				%for i=0 upto li: draw point i of P; endfor;
		enddef; 

		#<en> To change color of Mud area
		#<fr> Pour modifier la couleur de l'aire Boue
		def a_u_boue (expr p) =
			T:=identity;
			#thfill p withcolor (0.22, 0.22, 0.95);
			#126, 51, 0
			thfill p withcolor (0.49, 0.20, 0.00);
		enddef;

		#<en> To change color of Sump
		#<fr> Pour modifier la couleur de l'aire siphon
		def a_sump (expr p) =
			T:=identity;
			#thfill p withcolor (0.22, 0.22, 0.95);
			thfill p withcolor (0.06, 0.20, 0.65);
		enddef;

		#<en> To change color of guano
		#<fr> Pour modifier la couleur de l'aire guano
		def a_u_guano (expr p) =
			T:=identity;
			thfill p withcolor (0.53, 0.26, 0.11);
		enddef;
		
		#<en> To change color of a tree-trunk
		#     I advise to use a line "border" to delimit the area
		#	  If used with tree-leaves, add the option -place top
		#<fr> Pour modifier la couleur de l'aire tronc
		#	  Je suggère d'utiliser une ligne "border/bord" pour délimiter l'aire
		#	  Si utilisé conjointement avec l'aire feuilles d'arbres, utiliser l'option -place top
		def a_u_tronc (expr p) =
			T:=identity;
			thfill p withcolor (0.62, 0.24, 0.05);
		enddef;

		#<en> To change color of a tree-leaves
		#<fr> Pour modifier la couleur de l'aire feuilles d'arbre/feuillage
		def a_u_feuilles (expr p) =
			T:=identity;
			thfill p withcolor (0.0, 1.0, 0.0);
		enddef;

		#<en> To change color of Water area
		#<fr> Pour modifier la couleur de l'aire eau
		def a_water (expr p) =
			T:=identity;
			#thfill p withcolor (0.60, 0.8, 1);
			thfill p withcolor (0.17, 0.46, 1);
		enddef;

		#<en> Northarrow more funnier !
		#<fr> Pour définir une nouvelle flèche du nord
		def s_northarrow (expr rot) =
			begingroup
				interim defaultscale:=0.7; % scale your north arrow here
				#interim defaultscale:=0.5; % scale your north arrow here; 0.5 is the best value for atlas
				T:=identity scaled defaultscale rotated -rot;
				interim linecap:=squared;
				interim linejoin:=rounded;
				thfill (-.5cm,-.1cm)--(0,2.5cm)--(.5cm,-.1cm)--cycle;
				pickup pencircle scaled (0.08cm * defaultscale);
				thdraw (0,0)--(0,-2.5cm);
				pickup pencircle scaled (0.16cm * defaultscale);
				p:=(0.4cm,0.6cm);
				thdraw ((p--(p yscaled -1)--(p xscaled -1)--(p scaled -1)) shifted (0,-1.0cm));
				label.rt(thTEX("mg") scaled 1.6, (.6cm,-1.6cm)) transformed T;
			endgroup;
		enddef;

#		#<en> Change Scale bar type
#	 	#<fr> Pour modifier la barre d'échelle
#		def s_scalebar (expr l, units, txt) =
#			begingroup
#				interim warningcheck:=0;
#				tmpl:=l / Scale * cm * units / 2;
#				tmpx:=l / Scale * cm * units / 5;
#				tmph:=5bp; % bar height
#			endgroup;
#			pickup PenC;
#			draw (-tmpl,0)--(tmpl,0)--(tmpl,-tmph)--(-tmpl,-tmph)--cycle;
#			p:=(0,0)--(tmpx,0)--(tmpx,-tmph)--(0,-tmph)--cycle;
#			for i:=-2.5 step 2 until 2:
#				fill p shifted (i * tmpx,0);
#			endfor;
#			begingroup
#				interim labeloffset:=3.5bp;
#				for i:=0 step (l/5) until (l-1):
#					tmpx:=tmpl * (i * 2 / l - 1);
#					label.bot(thTEX(decimal (i)),(tmpx,-tmph));
#				endfor;
#				label.bot(thTEX(decimal (l) & "\thinspace" & txt),(tmpl,-tmph));
#				%<en> To write the scale "1:scale" uncomment it the next line:
#				%<fr> Pour écrire l'échelle "1:scale" au dessus de la barre décommenter la ligne suivante :
#				%label.top(thTEX("Echelle 1 : " & decimal (Scale*100)),(0,0));
#			endgroup;
#		enddef;

		
#		#<en> Write the point depth (not functionning...)
#		#<fr> Définir un point qui écrit la côte/profondeur (Ne fonctionne pas actuellement...)
#		def p_u_prof (expr pos) =
#			T:=identity shifted pos;
#			pickup PenD;
#			p:=(-.3u,0)--(.3u,0);
#			thdraw p; thdraw p rotated 90;
#			p:=fullcircle scaled .2u;
#			thclean p; thdraw p;
#		enddef;
#		vardef p_label@#(expr txt,pos,rot,mode) =
#			if mode=1:
#				thdrawoptions(withcolor .8red + .4blue);
#				p_u_prof(pos);
#				% append "m" to label
#				picture txtm;
#				% calcul profondeur
#				%numeric profondeur;
#				profondeur:=(\thaltitude-\cavemaxz);
#				picture txtprofondeur;
#				txtm:=image(
#					draw txt;
#					interim labeloffset:=0;
#					label.urt(btex \thaltitude m etex, lrcorner txt);
#					%label.urt(btex \thdepth m etex, lrcorner txt);
#				);
#				% give extra offset in case of l/r/t/b alignment
#				pair ctmp;
#				ctmp:=center thelabel@#("x", (0,0));
#				if (xpart ctmp * ypart ctmp)=0:
#					interim labeloffset:=(.4u);
#				else: % diagonal alignment
#					interim labeloffset:=(.2u);
#				fi;
#				% draw label
#				lab:=thelabel@#(txtm, pos);
#				draw lab _thop_; % use color
#				thdrawoptions();
#				bboxmargin:=0.8bp;
#				write_circ_bbox((bbox lab) smoothed 2);
#			else:
#				if mode=7: interim labeloffset:=(u/8) fi;
#				lab:=thelabel@#(txt, pos);
#				if mode>1: pickup PenD fi;
#				if mode=2: process_uplabel;
#				elseif mode=3: process_downlabel;
#				elseif mode=4: process_updownlabel;
#				elseif mode=5: process_circledlabel;
#				elseif mode=6: process_boxedlabel;
#				elseif mode=7: process_label(pos,rot);  % station name
#				elseif mode=8: process_filledlabel(pos, rot);
#				else: process_label(pos,rot); fi;
#    		fi;
#		enddef;



		#<en> Change the altitude definition
		#     This label requires to specify the position of text relative to point with
		#     help of -align in the options box.
		#<fr> Changer la définition du point altitude
		#     Ce label nécessite la position spécifique de l'étiquette de texte de façon relative
		#      au point avec l'aide de l'option -align.
		#ex: -align bottom-right/top-left/top-right/bottom-left/top/bottom/left/right...
		
		def p_altitude (expr pos) =
			T:=identity shifted pos;
			pickup PenD;
			p:=(-.3u,0)--(.3u,0);
			thdraw p; thdraw p rotated 90;
			p:=fullcircle scaled .2u;
			thclean p; thdraw p;
		enddef;
		vardef p_label@#(expr txt,pos,rot,mode) =
			if mode=1:
				thdrawoptions(withcolor .8red + .4blue);
				p_altitude(pos);
				% append "m" to label
				picture txtm;
				txtm:=image(
					draw txt;
					interim labeloffset:=0;
					label.urt(btex \thaltitude { m} etex, lrcorner txt);
					#label.urt(btex \thheight m etex, lrcorner txt);
				);
				% give extra offset in case of l/r/t/b alignment
				pair ctmp;
				ctmp:=center thelabel@#("x", (0,0));
				if (xpart ctmp * ypart ctmp)=0:
					interim labeloffset:=(.4u);
				else: % diagonal alignment
					interim labeloffset:=(.2u);
				fi;
				% draw label
				lab:=thelabel@#(txtm, pos);
				draw lab _thop_; % use color
				thdrawoptions();
				bboxmargin:=0.8bp;
				write_circ_bbox((bbox lab) smoothed 2);
			else:
				if mode=7: interim labeloffset:=(u/8) fi;
				lab:=thelabel@#(txt, pos);
				if mode>1: pickup PenD fi;
				if mode=2: process_uplabel;
				elseif mode=3: process_downlabel;
				elseif mode=4: process_updownlabel;
				elseif mode=5: process_circledlabel;
				elseif mode=6: process_boxedlabel;
				elseif mode=7: process_label(pos,rot);  % station name
				elseif mode=8: process_filledlabel(pos, rot);
				else: process_label(pos,rot); fi;
    		fi;
	  	enddef;

		#<en> For point height with P or C prefixe
		#     use “point 0 0 height -value [+10 m]”
		#     or “point 0 0 height -value [-85 m]”
		#     in your data to get E10 or P85
		#<fr> Pour obtenir un point de hauteur de passage avec P ou C comme préfixe
		#     utiliser “point 0 0 height -value [+10 m]”
		#     ou “point 0 0 height -value [-85 m]”
		#     dans les données vous donner E10 ou P85 respectivement
		verbatimtex \def\thheightpos{E}\def\thheightneg{P} etex


		#<en> Change the altitude definition for the wall-line label (add units)
		#	  To modify the color, you need to modify the triplets after the 3 withcolor command.
		#	  BE CAREFUL ! Sometimes, it generates mpost errors when using point wall:altitude.
		#		If you get this kind of error, comment the whole p_wallaltitude definition.
		#<fr> Changer la définition de l'altitude pour le label de la ligne mur (ajout de l'unité)
		#	  Pour modifier la couleur, modifier le triplet (RGB) après les 3 commandes withcolor.
		#	  ATTENTION ! Parfois, cette redéfinition génère des erreurs métapost.
		#		Si c'est le cas, commenter toute la redéfinition du point p_wallaltitude.
		
		def p_wallaltitude (expr pprev,pos,pnext,txt) =
			rot:=angle(unitvector(pnext-pos)+unitvector(pos-pprev)) - 90;
			pickup PenD;
			pair zz;
			%zz:=(pos + 3*unitvector(dir rot));
			zz:=(pos + (u/4)*unitvector(dir rot));
			%draw (pos)--zz withcolor (0.78, 0.08, 0.52); % tic in black
			draw (pos)--zz withcolor (0.78, 0.08, 0.52); % tic in color
			% add the unit (here, meters as m)
			txtm:=image(
					%draw txt; % altitude in black
					draw txt withcolor (0.78, 0.08, 0.52); % altitude in color
					%interim labeloffset:=0;
					%label.urt(btex \thaltitude { m} etex, lrcorner txt); % unit in black
					label.urt(btex \thaltitude { m} etex, lrcorner txt) withcolor (0.78, 0.08, 0.52); % unit in color
				);
			begingroup 
				%    interim labeloffset:=2pt;
				interim labeloffset:=(u/12);
				if horiz_labels:
					rot:=rot mod 360;
					if rot<=22.5: lab:=thelabel.rt(txtm, zz);
					elseif rot<=67.5: lab:=thelabel.urt(txtm, zz);
					elseif rot<=112.5: lab:=thelabel.top(txtm, zz);
					elseif rot<=157.5: lab:=thelabel.ulft(txtm, zz);
					elseif rot<=202.5: lab:=thelabel.lft(txtm, zz);
					elseif rot<=247.5: lab:=thelabel.llft(txtm, zz);
					elseif rot<=292.5: lab:=thelabel.bot(txtm, zz);
					elseif rot<=337.5: lab:=thelabel.lrt(txtm, zz);
					else: lab:=thelabel.rt(txtm, zz);
					fi;
				else:
					if (abs rot>90) and (abs rot <=270):
						rot:=rot-180;
						lab:=thelabel.lft(txtm, pos);
					else:
						lab:=thelabel.rt(txtm, pos);
						fi;
				fi;
				process_label(pos, if horiz_labels: 0 else: rot fi);		
			endgroup;
		enddef;
		
		
		
	#<en> Definition of new lines symbols
	#<fr> Définition de nouveau symboles de lignes


		#<en> Line symbol for strata for cross sections (u:strata). It works exactly as line section
		#     symbol but you should use -clip off option:
		#<fr> Symbole de ligne pour dessiner des strates (u:strata). 
		#     Cela fonctionne exactement comme les autres sections de ligne
		#     mais vous devrez rajouter l'option -clip off:
		def l_u_strata (expr P) =
			T:=identity;
			path Q; Q = punked P;
			for t = 0 upto length P - 1:
				pair zz[];
				zz1 := point t of P;
				zz2 := point t+1 of P;
				zz3 := postcontrol t of P;
				zz4 := precontrol t+1 of P;
				linecap:=0;
				if (length(zz3-1/3[zz1,zz2]) > 0.1pt) or (length(zz4-2/3[zz1,zz2]) > 0.1pt):
					zz5 = whatever[zz1,zz2];
					(zz3-zz5) = whatever * (zz1-zz2) rotated 90;
					pickup pencircle scaled 1 mm;
					draw zz1--zz5 dashed evenly;
					pickup PenA;
					draw zz1--zz5 withcolor background;
					zz6 = whatever[zz1,zz2];
					(zz4-zz6) = whatever * (zz1-zz2) rotated 90;
					pickup pencircle scaled 1 mm;
					draw zz2--zz6 dashed evenly;
					pickup PenA;
					draw zz2--zz6 withcolor background;
				else:
					pickup pencircle scaled 1 mm;
					draw zz1--zz2 dashed evenly;
					pickup PenA;
					draw zz1--zz2 withcolor background;
				fi;
			endfor;
		enddef;


		#<en> Line symbol for Coupoles (u:coupole). It works exactly as line section
		#<fr> Symbole de ligne pour dessiner des coupoles de plafond. 
		#     Fonctionne comme les autres lignes
		def l_u_coupole (expr P) = 
			T:=identity;
			cas := 0;                            % cursor to step along path
			dlzka := arclength P;
			mojkrok:=adjust_step(dlzka, 0.25u);  % symbol length nudged to be multiple of path length
			q:= (0.10u,0.16u) -- (0.13u,0.17u);         % dot
   
			pickup PenC;  %2nd thinnest pen
			forever:
				t := arctime cas of P;
				thdraw q rotated angle(thdir(P,t)) shifted (point t of P ); % draw dots
				cas := cas + mojkrok;
				exitif cas > dlzka + (mojkrok / 3); % for rounding errors
			endfor;
			pickup PenC;   %2nd thickest pen
			thdraw P;      %continuous line
		enddef;


		#<en> Line symbol for fault. 
		#     It works exactly as line section symbol but you should use -clip off option:
		#<fr> Symbole de ligne pour dessiner des failles (u:fault). 
		#     Cela fonctionne exactement comme les autres sections de ligne
		#     mais vous devrez rajouter l'option -clip off:
		def l_u_fault (expr P) =
			T:=identity;
			path Q; Q = punked P;
			pickup PenA;
			for t = 0 upto length P - 1:
				pair zz[];
				zz1 := point t of P;
				zz2 := point t+1 of P;
				zz3 := postcontrol t of P;
				zz4 := precontrol t+1 of P;
				if (length(zz3-1/3[zz1,zz2]) > 0.1pt) or (length(zz4-2/3[zz1,zz2]) > 0.1pt):
					zz5 = whatever[zz1,zz2];
					(zz3-zz5) = whatever * (zz1-zz2) rotated 90;
					draw zz1--zz5 dashed evenly;
					zz6 = whatever[zz1,zz2];
					(zz4-zz6) = whatever * (zz1-zz2) rotated 90;
					draw zz2--zz6 dashed evenly;
				else:
					draw zz1--zz2 dashed evenly;
				fi;
			endfor;
		enddef;


		#<en> Line symbol for the surface. 
		#     It works exactly as line section symbol but you should use -clip off option:
		#<fr> Symbole de ligne pour dessiner la surface (u:surf). 
		#     Cela fonctionne exactement comme les autres sections de ligne
		#     mais vous devrez rajouter l'option -clip off:
		def l_u_surf (expr P) =
			T:=identity;
			path Q; Q = punked P;
			pickup PenC;
			draw Q dashed evenly withcolor (0.5, 0, 0);	
		enddef;


		#<en> To add a doline line (u:doline); Do not forget the option -clip off !
		#<fr> Symbole de ligne pour dessiner une ligne doline (u:doline). 
		#     Cela fonctionne exactement comme les autres sections de ligne
		#     mais vous devrez rajouter l'option -clip off:
		def l_u_doline (expr P) =
			T:=identity;
			laenge:= arclength P;
			symsize:=adjust_step(laenge,2u);
			triangle_width:=symsize/10;
			cur:=(symsize-triangle_width)/2;
			pickup PenC;
			forever:
				t1 := arctime (cur) of P;
	 			t  := arctime (cur + triangle_width/2) of P;
				t2 := arctime (cur + triangle_width) of P;
				thfill (subpath (t1,t2) of P) --
					((point t of P) + symsize/2 * unitvector(thdir(P,t) rotated 90)) --
					cycle;
				thdraw (point t2 of P) --((point t of P) + symsize/2 * unitvector(thdir(P,t) rotated 90)) --
					(point t1 of P) withcolor (0.5, 0, 0);
				cur := cur + symsize;
				exitif cur > laenge - (1*symsize/3); % for rounding errors
				t1:=arctime (cur) of P;
			endfor;
		enddef;


		#<en> Defines the gradient as geologic dip
		#<fr> Définit le gradient comme pendage géologique
		def p_gradient_XA (expr P,R,S,A) =
			U:=(.15u, .4u);
			T:=identity aligned A rotated R scaled S shifted P;
			pickup PenC;
			thdraw (0u, 0u) -- (0u, .4u);
			thdraw (-.4u, 0u) -- (.4u, 0u);
		enddef;
		initsymbol ("p_gradient_XA");
		symbol-assign point gradient XA


		#<en> Section to define the bat symbol (point, line, area)
		#<fr> Section pour définir le symbole Chauve souris utilisé en point, ligne ou aire
		path bat_path_x;
		bat_path_x := (160.43589,619.76148)
		.. controls (200.83034,598.56215) and (225.01974,599.82632) .. (242.33709,601.15842)
		.. controls (250.91988,585.02142) and (280.12279,545.7622) .. (328.92385,566.52372)
		.. controls (343.18917,529.89929) and (387.77695,513.04018) .. (453.54702,518.36185)
		.. controls (456.6654,525.97557) and (466.09064,533.43257) .. (471.27843,523.05007)
		.. controls (463.85291,520.67657) and (466.71891,517.42483) .. (471.63814,522.23522)
		.. controls (472.87859,519.83044) and (472.11254,517.25674) .. (467.00984,516.24193)
		.. controls (498.08181,494.38071) and (518.37927,488.7935) .. (554.08261,484.34703)
		.. controls (536.23968,468.87122) and (526.7451,451.32142) .. (536.0878,433.78585)
		.. controls (539.04313,428.23891) and (549.65293,437.81051) .. (550.08905,431.99134)
		.. controls (543.35122,428.68782) and (547.16851,429.31755) .. (550.93619,430.90592)
		.. controls (555.01514,419.20795) and (542.29889,420.82043) .. (539.21019,422.32967)
		.. controls (526.80565,412.03922) and (538.14174,362.22955) .. (562.04206,325.41289)
		.. controls (560.70416,305.4475) and (552.94665,275.48765) .. (596.42383,240.15823)
		.. controls (586.13796,214.86512) and (584.21841,176.344) .. (618.88684,158.99293)
		.. controls (600.38363,161.42082) and (571.90452,163.00167) .. (555.87287,173.29962)
		.. controls (533.80922,180.31406) and (511.7587,189.77279) .. (494.76462,217.75852)
		.. controls (469.02274,260.15007) and (465.60841,280.08537) .. (466.27659,287.73284)
		.. controls (467.27295,299.13663) and (456.20597,295.4343) .. (455.42733,284.84646)
		.. controls (447.034,297.47822) and (465.71846,292.96944) .. (457.40227,311.17742)
		.. controls (451.51715,333.88534) and (454.55183,344.68208) .. (455.22274,365.27634)
		.. controls (445.59186,380.66207) and (438.52169,394.98144) .. (432.56329,406.97544)
		.. controls (421.27321,411.75599) and (411.86904,413.85884) .. (403.92838,423.33244)
		.. controls (391.19793,418.79449) and (380.875,414.46152) .. (373.6673,409.41976)
		.. controls (365.11095,413.84661) and (372.76761,437.1554) .. (372.88328,437.30963)
		-- (360.72573,447.88215)
		.. controls (360.72573,447.88215) and (348.36583,439.38367) .. (342.32921,440.26049)
		.. controls (340.52016,451.25937) and (343.58923,463.9528) .. (354.67087,475.2679)
		.. controls (341.63825,482.57642) and (339.10347,494.24676) .. (313.80723,490.57484)
		.. controls (304.61922,489.24114) and (282.31298,490.61764) .. (258.32359,496.84657)
		.. controls (246.18809,499.99759) and (248.48311,482.8706) .. (236.36849,493.22467)
		.. controls (239.32461,491.85429) and (242.55704,492.01948) .. (245.59044,495.64662)
		.. controls (248.83726,499.52895) and (249.4495,502.08244) .. (244.59097,503.87878)
		.. controls (221.93401,514.80409) and (190.83965,541.85436) .. (178.69512,574.11392)
		.. controls (176.80431,577.00681) and (162.4873,600.33708) .. cycle;
		path bat_path_bb;
		bat_path_bb = bbox bat_path_x;
		path bat_path;
		bat_path = bat_path_x shifted (-(llcorner bat_path_bb) - (urcorner bat_path_bb - llcorner bat_path_bb) / 2.0) scaled (1u / ((xpart urcorner bat_path_bb) - (xpart llcorner bat_path_bb))) rotated 210;

		#<en> Section of your layout define point u:bats symbol like this
		#<fr> Pour définir le point chauve souris : u:bats
		def p_u_bats(expr pos, theta, sc, al) =
			T := identity shifted pos;
			thfill (bat_path scaled 1.5) withcolor black;
		enddef;

		#<en> similarly the line u:bat symbol
		#<fr> Idem pour la ligne
		def l_u_bats(expr P) =
			T:=identity;
			cas := 0;
			dlzka := arclength P;
			mojkrok:=adjust_step(dlzka, 1.0u);
			pickup PenD;
			forever:
				t := arctime cas of P;
				thfill bat_path scaled 0.5 shifted (point t of P) withcolor black;
				cas := cas + mojkrok;
				exitif cas > dlzka + (mojkrok / 3); % for rounding errors
			endfor;
		enddef;

		#<en> and finally the area u:bat symbol (pattern in this case)
		#<fr> Et pour l'aire
		% bat pattern
		beginpattern(pattern_bat);
			fill bat_path withcolor black;
		endpattern;

		% bat area symbol
		def a_u_bats (expr Path) =
			T:=identity;
			thclean Path;
			thfill Path withpattern pattern_bat;
		enddef;

		#<en> These symbols will be included also in the legend. To
		#     change the way how they are drawn there just define appropriate
		#     macro. Its name should be symbol macro name with <code>_legend</code>
		#     suffix.
		#<fr> Ces symbols seront inclus dans la légende. Pour modifier la façon dont ils
		#     sont dessinés, juste, définissez la macro appropriée.
		#     Son nom doit être le nom de la macro symbol approprié avec le suffixe 
		#     <code>_legend</code>.
		def l_u_bats_legend =
			l_u_bats(((.2,.2) -- (.8,.8)) inscale)
		enddef;


		#<en> Definition of a stalagmite boss symbol
		#<fr> Définition du point stalagmite boss
		def p_u_boss (expr pos,theta,sc,al)=
			T:=identity aligned al rotated theta scaled sc shifted pos;
			pickup PenD;
			p := (0.08u,0.25u)..(0,0.29u)..(-0.08u,0.25u);
			q := (0.16u,0.5u)..(0u,0.58u)..(-0.16u,0.5u);
			for i=0 upto 9:
				# braun color
				thdraw p rotated 36i withcolor (100, 0.6, 0.2);
				thdraw q rotated 36i withcolor (100, 0.6, 0.2);
				% black color
				%thdraw p rotated 36i;
				%thdraw q rotated 36i;
			endfor
			p := fullcircle scaled 0.15u;
			thdraw p withcolor (100, 0.6, 0.2);
			% black color
			%thdraw p withcolor;
		enddef;


		#<en> Definition of a shell limestone symbol
		#<fr> Définition du point coquille fossile
		def p_u_shell (expr pos,theta,sc,al)=
			T:=identity shifted pos;
			pickup PenB;
			numeric turns, radius;
			path ss, cesta;
			pair za, zb;
			turns = 1.55;
			radius = .3u;
			za = ( xpart(origin)+0, ypart(origin)+.1u ) rotated 370 turns;
			zb = ( xpart(origin)+.3u, ypart(origin)+0 ) rotated 360 turns;
			cesta := za--zb;
			ss := (origin for t=1 upto 360 turns: -- dir t scaled t endfor) scaled (radius/turns/360);
			thdraw ss withcolor (0.3);
			thdraw (cesta cutbefore ss) withcolor (0.6);
		enddef;
		initsymbol ("p_u_shell");

		
		#<en> Define Danger symbol
		#<fr> Définition du point Danger
		def p_u_danger (expr P,R,S,A)=
			T:=identity aligned A rotated R scaled S shifted P;
			thfill (0,-u)--(u,0)--(0,u)--(0,.9u)--(.9u,0)--(0,-.9u)--cycle;
	    	thfill (0,-u)--(-u,0)--(0,u)--(0,.9u)--(-.9u,0)--(0,-.9u)--cycle;
			thfill (.1u,-.45u)..(0,-.35u)..(-.1u,-.45u)..(0,-.55u)..cycle;
			thfill (0,-.2u)..(.1u,-.1u)--(.2u,.4u)..(0,.6u)..(-.2u,.4u)--(-.1u,-.1u)..cycle;
		enddef;
		#initsymbol("p_entrance_MY");
		#let p_entrance = p_entrance_MY;
		

		#<en> Define dive line (u:ariane) in thin red
		#<fr> Définition de la ligne file d'Ariane en rouge fin
		def l_u_ariane (expr Path) =
			T:=identity;
			pickup PenD;
			draw Path withcolor (100, 0, 0);
		enddef;

					
		#<en> Definition of plankwalk
		#<fr> Définition d'une ligne de main courante
		def l_u_plankwalk  (expr P) = T:=identity;
			# by Dave Clucas
    		cas := 0;
	    	dlzka := arclength P;
    		mojrok := adjust_step(dlzka, 0.5u);
	    	pickup PenD;
			forever:
				t := arctime cas of P;
				thdraw ((point t of P) + 0.5 * u * unitvector(thdir(P,t) rotated 90)) --
				((point t of P) - 0.5 * u * unitvector(thdir(P,t) rotated 90) );
				cas := cas + mojrok;
				exitif cas > dlzka + (mojrok/3);  % for rounding errors
			endfor;
			pickup PenC;
			%thdraw P; 
			%draw path withcolor (0.5, 0 ,0)
		enddef;

		
		#<en> Definition of a line rail
		#<fr> Définition d'une ligne rail
		def l_u_rail (expr P) = 
			# by Andrew Aktinson
			T:=identity;
			cas := 0;
			dlzka := arclength P;
			mojkrok:=adjust_step(dlzka, 0.8u);
			pickup PenC;
			forever:
				t0 := arctime (cas) of P;
				t1 := arctime (cas + mojkrok*2/5) of P;
				t  := arctime (cas + mojkrok/2) of P;
				t4 := arctime (cas + mojkrok*3/5) of P;
				t5 := arctime (cas + mojkrok) of P;
				thdraw (subpath (t0,t1) of P);
				thdraw (subpath (t4,t5) of P);
				drawdot
				(point t of P);
				#mark_ (P,t,0.02u);
				#mark_ (P,t,-0.02u);
				#f := (P,t,0.2u);
				#draw f;
				cas := cas + mojkrok;
				exitif cas > dlzka - (2*mojkrok/3); % for rounding errors
			endfor;
		enddef;


		#<en> Change fig Flowstone, increase the number of arcs
		#<fr> Modifier le symbole flowstone en augmentant le nombr d'arc
		def l_flowstone (expr p) =
			#draw p withpen PenC withcolor (0.0, 0.5, 1.0);
			T:=identity;
			cas := 0;
			dlzka := arclength p;
			mojkrok:=adjust_step(dlzka, .3u);
			# povodne .7u
			pickup PenC;
			t1:=0;
			forever:
				t2 := arctime (cas + mojkrok) of p;
				thdraw (point t1 of p){dir (angle(thdir(p,t1)) + 60)} ..
						{dir (angle(thdir(p,t2)) - 60)}(point t2 of p);
				cas := cas + mojkrok;
				exitif cas > dlzka + (mojkrok / 3); % for rounding errors
				t1:=t2;
			endfor;
		enddef;


		#<en> Point that represents a bird nest 
		#<fr> Point pour représenter un nid d'oiseau		
		def p_u_nid (expr pos,theta,sc,al)=
			U:=(.4u,.2u);
			T:=identity aligned al rotated theta scaled sc shifted pos;
			pickup PenC;
			#thdraw (-.4u,.2u){dir -70}..{dir 70}(.4u,.2u) withcolor (0.53, 0.26, 0.11);
			thdraw (-.2u,.1u){dir -70}..{dir 70}(.2u,.1u) withcolor (0.53, 0.26, 0.11);
		enddef;

		
		#<en> Artificial anchor point (From a post by Evaristo Quiroga)
		#<fr> Point ancrage artificiel (From a post by Evaristo Quiroga)
		def p_u_anchor_artificial(expr pos,theta,sc,al) =
			T:=identity shifted pos;
			thdraw origin withpen pencircle scaled 0.25u withcolor (0.58, 0.44, 0.25);
		enddef;
		initsymbol ("p_u_anchor_artificial");


		#<en> Natural anchor point (From a post by Evaristo Quiroga)
		#<fr> Point ancrage naturel (From a post by Evaristo Quiroga)
		def p_u_anchor_natural(expr pos,theta,sc,al) =
			U:=(.2u,.2u);
			T:=identity aligned al rotated theta scaled sc shifted pos;
			thfill (-.2u,-.2u)--(0,.2u)--(.2u,-.2u)--cycle withcolor (0.58, 0.44, 0.25); 
		enddef;
		initsymbol ("p_u_anchor_natural");


		#<en> Deviation line (by Tarquin 2019)
		#<fr> Ligne pour dessiner une déviation (D'après Tarquin 2019)
		def l_u_deviation (expr P) =
			begingroup;
				save ellipse;
				T:=identity;
				pickup PenC;
				path ellipse;
				 ellipse:=fullcircle xscaled (.5u) yscaled (.25u) shifted (point (length P) of P);
				thdraw P cutafter ellipse;
				draw ellipse;
			endgroup;
		enddef;
		initsymbol("l_u_deviation");
		def l_u_deviation_legend =
		l_u_deviation(((.1,.5)--(.8,.5)) inscale);
		enddef;


		#<en> Climbing caver point (by Juraj Halama, 2020)
		#	  Climbing one has center where the rope should go on the harness...
		#<fr> Point pour dessiner un spéléo qui grimpe ou escalade (D'après Juraj Halama, 2020)
		#	  Le point correspond au centre du spéléo au niveau du harnais, qui doit donc être sur la corde
		picture u_man_c_pic;
			u_man_c_pic := image (
				draw (0cm, -0cm) -- (-8cm, 27cm) -- (-36cm, 55cm) -- (-50cm, 99cm) withpen pencircle scaled 16cm;
				draw (27cm, 48cm) -- (0, 64cm) -- (-29cm, 61cm) -- (-38cm, 102cm)  withpen pencircle scaled 16cm;
				draw (-65cm, 48cm) -- (-75cm, 75cm) -- (-53cm, 106cm) -- (0, 106cm) withpen pencircle scaled 14cm;
				draw (-44cm, 130cm) withpen pencircle scaled 27cm withcolor black;
			) shifted (20cm, -67cm);

		def p_u_man_c (expr P, R, S, A) =
			U := (60cm, 85cm) scaled (0.01 / Scale);
			T:=identity aligned A rotated R scaled S shifted P;
			thdraw u_man_c_pic scaled (0.01 / Scale);
		enddef;
		initsymbol ("p_u_man_c");

		#<en> The scale on the map and in the legend is matching just for 1:500...
		#<fr> L'échelle sur la carte et sur la légende correspond au 1:500...
		def p_u_man_c_legend =
			draw u_man_c_pic scaled (u / 175cm) shifted ((.5, .5) inscale);
		enddef;


		#<en> Walking caver point (by Juraj Halama, 2020)
		#	  Use "-align top" for proper alignment of the walking man when his point is on the groung.
		#<fr> Point pour dessiner un spéléo marchant (D'après Juraj Halama, 2020)
		#	  Utiliser l'option "-align top" pour un alignement correct quand le point est au sol
		picture u_man_w_pic;
			u_man_w_pic := image (
				draw (0, 0) -- (7.5cm, 36cm) -- (0cm, 69cm) -- (9cm, 99cm) withpen pencircle scaled 16cm;
				draw (42cm, 9cm) -- (37.5cm, 42cm) -- (13.5cm, 69cm) -- (30cm, 102cm) withpen pencircle scaled 16cm;
				draw (21.5cm, 100.5cm) -- (6.6cm, 69cm) withpen pencircle scaled 16cm;
				draw (-24cm, 75cm) -- (-13.5cm, 102cm) -- (9cm, 112.5cm) -- (30cm, 108cm) -- (51cm, 87cm) -- (75cm, 93cm) withpen pencircle scaled 14cm;
				draw (30cm, 132cm) withpen pencircle scaled 27cm withcolor black;
			) shifted (-20cm, -70cm);

		def p_u_man_w (expr P, R, S, A) =
			U := (60cm, 80cm) scaled (0.01 / Scale);
			T:=identity aligned A rotated R scaled S shifted P;
			thdraw u_man_w_pic scaled (0.01 / Scale);
		enddef;
		initsymbol ("p_u_man_w");

		#<en> The scale on the map and in the legend is matching just for 1:500...
		#<fr> L'échelle sur la carte et sur la légende correspond au 1:500...
		def p_u_man_w_legend =
			draw u_man_w_pic scaled (u / 175cm) shifted ((.5, .5) inscale);
		enddef;


		#<en> Plan view symbol point (by Juraj Halama, 2020)
		#<fr> Point dessinant un symbole de "vue en plan" (D'après Juraj Halama, 2020)
		def p_u_symbol_plan (expr pos,theta,sc,al) =
			U := (-3.25u, 3.25u);
			T := identity aligned al rotated theta scaled sc shifted pos;
			pickup PenB;
			q := ((-3.26u, -.95u) -- (1.74u, -.95u) -- (2.8u, .82u) -- (-1.49u, .82u) -- cycle);
			thfill q withcolor .85;
			thdraw q;
			q := ((-.175u, .5u) -- (0u, 0u) -- (.175u, .5u) .. (0u, .45u) .. cycle);
			thfill q withcolor .5green;
			thdraw q withcolor .5green;
			thdraw (0u, 0u) -- (0u, 2.31u) withcolor .5green; 
		enddef;


		#<en> Extended view symbol point (by Juraj Halama, 2020)
		#<fr> Point dessinant un symbole de "vue en coupe développée" (D'après Juraj Halama, 2020)
		def p_u_symbol_extend (expr pos,theta,sc,al) =
			U := (-2.5u, 2.5u);
			T := identity aligned al rotated theta scaled sc shifted pos;
			pickup PenB;
			q := ((-2.346u, -2.480u) -- (-.48u, -2.116u) -- (-.48u, 1.573u) -- (-2.346u, 1.354u) -- cycle);
			thfill q withcolor .85;
			q := ((-1.551u, -2.878u) -- (1.438u, -.766u) -- (1.438u, 2.388u) -- (-1.551u, 1.118u) -- cycle);
			thfill q withcolor .75;
			thdraw q;
			thdraw (-.48u, -2.116u) -- (-.48u, 1.573u) dashed evenly;
			q := ((.446u, -1.461u) -- (2.120u, -1.094u) -- (2.120u, 2.184u) -- (.446u, 1.965u) -- cycle);
			thfill q withcolor .85;
			thdraw (.446u, -1.461u) -- (.446u, 1.965u) dashed evenly;
			q := ((-.175u, .5u) -- (0u, 0u) -- (.175u, .5u) .. (0u, .45u) .. cycle) rotated -90;
			thfill q withcolor .5green;
			thdraw q withcolor .5green;
			thdraw (0u, 0u) -- (2.31u, 0u) withcolor .5green; 
		enddef;


		#<en> Change rope line color
		#<fr> Changer la couleur de la ligne rope (corde)
		symbol-colour line rope [58 44 25]

	
		#<en> Area for galerie initiation
		#     You will probably need to adapt the color to match the color of your galeries
		#<fr> Aire pour matérialiser le départ d'une galerie
		#     A adapter en fonction de la couleur de vos galeries
		def a_u_galerie(expr P) =
			T:=identity;
			## jaune chamois (208, 192, 122)
			##thfill P withcolor (0.82,0.75,0.48) withtransparency 0.5;
			thfill P withcolor (0.82,0.75,0.48) withalpha 0.5;

			## Grey
			##thfill P withcolor (0.73,0.72,0.75) withtransparency 0.5;
			#thfill P withcolor (0.73,0.72,0.75) withalpha 0.5;

			## Jaune queue de vache (168, 152, 116)
			##thfill P withcolor (0.66,0.60,0.45) withtransparency 0.5;
			#thfill P withcolor (0.66,0.60,0.45) withalpha 0.5;

			## gris argile (239, 239, 239)
			##thfill P withcolor (0.937,0.937,0.937) withtransparency 0.5;
			#thfill P withcolor (0.937,0;937,0.937) withalpha 0.5;
		enddef;
		
		
		#<en> Make unsurveyed wall lines light-weight and dashed
		#<fr> Rendre les parois non topographiées plus légères et en pointillés
		#Bruce Mutton 2010.06.20 for Therion 5.3.9
		def l_wall_unsurveyed (expr P) = 
			T:=identity;
			pickup PenC;
			thdraw P dashed evenly scaled (0.5*optical_zoom);
		enddef;
		
		
		#<en> thin grey cave splays, yellow duplicates and dashed approximate legs
		#<fr> Pour modifier la couleur du squelette en fonction du type de visées 
		#     (splays, normal, duplicates, approximate...)
		def l_survey_cave (expr P) =
			% always draws full centreline, rather than short stubs like default cave centrelines
			T:=identity;
			pickup PenC;
			if ATTR__shotflag_splay:
				drawoptions(withcolor(0.5,0.5,0.5) withpen PenD);
				thdraw P; %  grey & thin
				drawoptions();
			else: % not splay but may have either or both duplicate and approx flags set
				if ATTR__shotflag_duplicate: 
					drawoptions(withcolor (1,1,0)); % differentiate duplicate with colour yellow
				fi;
				if ATTR__shotflag_approx:
					thdraw P dashed evenly scaled optical_zoom;	% differentiate approx with dashed
				else:
					thdraw P;
				fi;	
				thdrawoptions();
			fi;
		enddef;

	endcode
	# Endcode for all the definition


	code tex-map
		\newtoks\thversiontitleB \thversiontitleB={Therion }
	endcode

endlayout

#------------------------------
layout scalebar_horiz

	#<en> Layout to define a horizontal Scale bar
	#<fr> Layout pour définir une barre d'échelle horizontale

	code metapost
 		#<en> Change Scale bar type
	 	#<fr> Pour modifier la barre d'échelle
		def s_scalebar (expr l, units, txt) =
			begingroup
				interim warningcheck:=0;
				tmpl:=l / Scale * cm * units / 2;
				tmpx:=l / Scale * cm * units / 5;
				tmph:=5bp; % bar height
			endgroup;
			pickup PenC;
			draw (-tmpl,0)--(tmpl,0)--(tmpl,-tmph)--(-tmpl,-tmph)--cycle;
			p:=(0,0)--(tmpx,0)--(tmpx,-tmph)--(0,-tmph)--cycle;
			for i:=-2.5 step 2 until 2:
				fill p shifted (i * tmpx,0);
			endfor;
			
			begingroup
				interim labeloffset:=3.5bp;
				for i:=0 step (l/5) until (l-1):
					tmpx:=tmpl * (i * 2 / l - 1);
					label.bot(thTEX(decimal (i)),(tmpx,-tmph));
				endfor;
				label.bot(thTEX(decimal (l) & "\thinspace" & txt),(tmpl,-tmph));
				%<en> To write the scale "1:scale" uncomment it the next line:
				%<fr> Pour écrire l'échelle "1:scale" au dessus de la barre décommenter la ligne suivante :
				%label.top(thTEX("Echelle 1 : " & decimal (Scale*100)),(0,0));
			endgroup;
		enddef;
	endcode

endlayout

#------------------------------
layout scalebar_vert-Halama

	#<en> Layout to define a vertical Scale bar (see Therion Wiki - Juraj Halama)
	#	  distributed under the GNU General Public Licence
	#	  You need to place it with in your thconfig file:
	#		code tex-map
	#			\def\maplayout{
    #			\legendbox{102.5}{100.4}{NW}
    #			{\scalebar}}
	#		endcode
	#<fr> Layout pour définir une barre d'échelle verticale (voir le wiki Therion - Jural Halama)
	#	  distribué sous la licence GNU General Public Licence
	#	  Il faut l'appeler dans le fichier de configuration thconfig avec le bloc:
	#		code tex-map
	#			\def\maplayout{
    #			\legendbox{102.5}{100.4}{NW}
    #			{\scalebar}}
	#		endcode

	code metapost
		def s_scalebar (expr l, units, txt) =
			begingroup
				tmpw = 3.0 bp;
				tmp5m = 5 / Scale * units * cm;
				tmpl = l / Scale * units * cm;
			endgroup;
			p := (0, 0) -- (tmpw, 0) -- (tmpw, - tmp5m) -- (0, - tmp5m) -- cycle; 
			pickup PenD;
			for i := 0 step 1 until (l - 1) / 5:
				if (i mod 2) <> 0:
					unfill p shifted - (0, i * tmp5m);
				else:
					fill p shifted - (0, i * tmp5m);
				fi;
				draw p shifted - (0, i * tmp5m);
			endfor;    
			pickup PenA
			%draw (-tmpw, 0) -- (tmpw, 0);
			%draw (-tmpw, -tmpl) -- (0, -tmpl);
			fill (-2tmpw, tmpw) -- (-2tmpw, -tmpw) -- (0, 0) -- cycle;
			fill (-2tmpw, -tmpl + tmpw) -- (-2tmpw, -tmpl + -tmpw) -- (0, -tmpl) -- cycle;
			if ((l mod 10) > 5) or ((l mod 10) = 0):
				draw (0, - tmpl) -- (tmpw, - tmpl) withcolor black;
			else:  
				draw (0, - tmpl) -- (tmpw, - tmpl) withcolor white;
			fi;       
			begingroup
				interim labeloffset:=3.5bp + tmpw;
				%interim defaultscale:=0.5;
				label.rt(thTEX("\size[12]" & "0{\thinspace}m"),(0, 0));
				for i := 1 step 1 until l / 5:
					if (i mod 10) = 0:
						label.rt(thTEX("\size[12]" & "-\thinspace" & decimal (i * 5)),(0, - i * tmp5m));
					else:
						if i * 5 = l:
							label.rt(thTEX("\size[12]" & "-\thinspace" & decimal (i * 5)),(0, - i * tmp5m));
						else:  
							label.rt(thTEX("\size[8]" & "-\thinspace" & decimal (i * 5)),(0, - i * tmp5m));
						fi  
					fi;  
        		endfor;
				if (l mod 5) <> 0:
					label.rt(thTEX("\size[12]" & "-\thinspace" & decimal (l)),(0, - tmpl));
				fi;
			endgroup
		enddef;                
	endcode

endlayout

#------------------------------
layout scalebar_vert

	#<en> Layout to define a vertical Scale bar
	#<fr> Layout pour définir une barre d'échelle verticale

	code metapost
 		#<en> Change Scale bar type
	 	#<fr> Pour modifier la barre d'échelle
		def s_scalebar (expr l, units, txt) =
			begingroup
				interim warningcheck:=0;
				tmpl:=l / Scale * cm * units / 2;
				tmpx:=l / Scale * cm * units / 5;
				tmph:=5bp; % bar height
				% To compute the right size of the text
				if (l/1000) <1 :
					if (l/100) <1 :
						if (l/10) <1 : tmphz:=6bp;
						else: tmphz:=8bp; fi;
					else: tmphz:=10bp; fi;
				else tmphz:=12bp; fi;
			endgroup;
			pickup PenC;
			draw (0,-tmpl)--(0,tmpl)--(-tmph,tmpl)--(-tmph,-tmpl)--cycle;
			p:=(0,0)--(0,tmpx)--(-tmph,tmpx)--(-tmph,0)--cycle;
			for i:=-2.5 step 2 until 2:
				fill p shifted (0,i * tmpx);
			endfor;
			begingroup
				interim labeloffset:=0bp;
				for i:=0 step (l/5) until (l-1):
					tmpx:=tmpl * (i * 2 / l - 1);
					label.bot(thTEX(decimal (l-i)),(tmph+tmphz,tmpx));
					%label.bot(thTEX(decimal (i)),(tmpx,-tmph)) rotated 90;
					% Inverser l'ordre des nombres
				endfor;
				label.bot(thTEX(decimal (l-l) & "\thinspace" & txt),(tmph+tmphz,tmpl));
				%label.bot(thTEX(decimal (l) & "\thinspace" & txt),(tmpl,-tmph)) rotated 90;
			endgroup;
		enddef;
	endcode
endlayout


#------------------------------
layout headerl
#<en> Layout to change the header (plan projection)
#     This code is experimental redefinition of map header and based on the work of
#     Bruce Mutton           Therion 5.3.15 make use of new variables
#<fr> Layout pour modifier le cartouche (header) de la projection en plan
#     Ce code de redéfinition est expérimental experimental et basé sur le travail de
#     Bruce Mutton           Therion 5.3.15 fait appel à de nouvelles variables

	copy scalebar_horiz

	#<en> This one affects maps only
	#<fr> Ceci ne touche que les maps (plans)
	code tex-map
		
		\legendcontent={%
			\hsize=\legendwidth
			\color[0 0 0]\the\legendtextcolor
			\ifnortharrow\vbox to 0pt{\line{\hfil\northarrow}\vss}\fi
			%print cave map name
			\edef\tmp{\the\cavename} \ifx\tmp\empty \else
				{\the\legendtextheadersize\the\cavename}\vskip0.5cm
			\fi
			%print comment
			{\rightskip=0pt plus 3em\parskip=3bp
			\edef\tmp{\the\comment} \ifx\tmp\empty \else
				{\the\legendtextsize\the\comment} \par\medskip\vskip1cm
			\fi}
			%print scalebar
			\ifscalebar\scalebar\vskip1cm\fi
		%print entrances coordinates (Lat-Long/WGS84) if defined
		\edef\tmp{\the\ECoordinates} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thcoords: \ss\the\ECoordinates\par}
			\vskip0.5cm
		\fi

		% start bruces addition
		# %    CS
		\edef\tmp{\the\outcsname} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thproj: \ss\the\outcsname\par}
		\fi
		\edef\tmp{\the\northdir} \ifx\tmp\empty \else
			{\the\legendtextsize\ss\the\northdir north }
		\fi
		\edef\tmp{\the\magdecl} \ifx\tmp\empty \else
			{\the\legendtextsize\ss\the\magdecl { deg.} \par}
		\fi
		\vskip0.5cm
		% end bruces addition
		#%print comment
		{
		#\rightskip=0pt plus 3em\parskip=3bp
		#\edef\tmp{\the\comment} \ifx\tmp\empty \else
		#	{\the\legendtextsize\the\comment} \par\medskip
		#\fi
		%print cavelength and depth
		\everypar{\hangindent=2em\hangafter=1}
		\edef\tmp{\the\cavelength} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cavelengthtitle: \ss\the\cavelength\par}
		\fi
		\edef\tmp{\the\cavedepth} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cavedepthtitle: \ss\the\cavedepth\par}
		\fi
		# % start bruces addition
		## %      altitude
		#\edef\tmp{\the\cavemaxz} \ifx\tmp\empty \else
		#	{\the\legendtextsize\si\the\depthrangetitle \ss\the\cavemaxz m to}
		#\fi
		#\edef\tmp{\the\caveminz} \ifx\tmp\empty \else
		#	{\the\legendtextsize\ss\the\caveminz m \par} %above mean sea level
		#\fi
		# % end bruces addition

		%print explorers names
		\edef\tmp{\the\exploteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\explotitle: \ss\the\exploteam\quad\si\the\explodate\par}
		\fi
		%print surveyors names
		\edef\tmp{\the\topoteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\topotitle: \ss\the\topoteam\quad\si\the\topodate\par}
		\fi
		 %%print the guides
		\edef\tmp{\the\guide} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thguide: \ss\the\guide\par}
		\fi
		%print cartographers names
		\edef\tmp{\the\cartoteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cartotitle: \ss\the\cartoteam\quad\si\the\cartodate\par}
		\fi
		%print synthesys name !!!  !!! with newtoks\synth \synth={Synth Name} in the thconfig
		\edef\tmp{\the\synth} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thsynth: \ss\the\synth\par}
		\fi
		%print the club
		\edef\tmp{\the\club} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thclub: \ss\the\club\par}
		\fi
		%%print the expedition
		\edef\tmp{\the\expe} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thexpe: \ss\the\expe\par}
		\fi
        %%print the web page
		\edef\tmp{\the\wpage} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thwpage: \ss\the\wpage\par}
		\fi
		# % start bruces addition (compilation version and date modified to use built-in 5.3.15 variables)
		\edef\tmp{\the\thversion} \ifx\tmp\empty \else  %only write version and date if version is not emplty
			{\the\legendtextsize\si\the\thversiontitleA: \ss\the\thversiontitleB \ss\the\thversion}
		% \fi
		% \edef\tmp{\the\currentdate} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\datetitle \ss\the\currentdate\par}
		\fi

		# % end bruces addition
		%print copyrights
		\edef\tmp{\the\copyrights} \ifx\tmp\empty \else
			{\the\legendtextsize\ss\the\copyrights\par}
		\fi
		
		\bigskip
		\edef\tmp{\the\thanksto} \ifx\tmp\empty \else
				{\the\legendtextsize\si\the\ththanksto: \ss\the\thanksto\par}
				%\def\ththankstotitle{Nos remerciements : }
				%{\everypar{\hangindent=7.2em\hangafter=1}
				%\size[\thsizem]\si\ththankstotitle \ss\ththanksto\par}
		\fi
		}
		\formattedlegend
		\color[0 0 0]
		}

	endcode
endlayout


#------------------------------
layout header_coupe_vert-to-place
#<en> Layout to change the header (extended elevation)
#     This code is experimental redefinition of map header
#     Bruce Mutton           Therion 5.3.15 make use of new variables
#	  Xavier Robert (2020/04/27)
#     Header specifically for extended elevation maps with a vertical scale bar 
#     that needs to be manually located inside your layout (in the thconfig file)
#     with the code :
#       	code tex-map
#          		\def\maplayout{
#				\legendbox{0}{-1}{NW}{\the\legendcontent}	% add legend content
#				\legendbox{0}{87.5}{NW}{\hsize=1.5 cm\centerline\scalebar}	% add scalebar where you want it
#				}
#			endcode
#<fr> Layout pour modifier le cartouche (header) de la projection en coupe développée
#     Ce code de redéfinition est expérimental experimental et basé sur le travail de
#     Bruce Mutton           Therion 5.3.15 fait appel à de nouvelles variables
#	  Xavier Robert (2020/04/27)
#     Header développé spécialement pour les coupes étendues et projetées, avec l'échelle
#     verticale qu'il faut localiser grâce au code :
#       	code tex-map
#          		\def\maplayout{
#				\legendbox{0}{-1}{NW}{\the\legendcontent}	% Ajout du contenu de la légende
#				\legendbox{0}{87.5}{NW}{\hsize=1.5 cm\centerline\scalebar}	% Ajout de l'échelle où nous la voulons
#				}
#			endcode


	copy scalebar_vert			# Xavier robert
	#copy scalebar_vert-Halama	# Juraj Halama

	#<en> This one affects maps only (extended view)
	#<fr> Ceci ne touche que les maps (coupes développées)
	code tex-map
		\legendcontent={%
			\hsize=\legendwidth
			\color[0 0 0]\the\legendtextcolor
			%\ifnortharrow\vbox to 0pt{\line{\hfil\northarrow}\vss}\fi
			%print cave map name
			\edef\tmp{\the\cavename} \ifx\tmp\empty \else
				{\the\legendtextheadersize\the\cavename}\vskip0.5cm
			\fi
			%print comment
			{\rightskip=0pt plus 3em\parskip=3bp
			\edef\tmp{\the\comment} \ifx\tmp\empty \else
				{\the\legendtextsize\the\comment} \par\medskip\vskip0.5cm
			\fi}
		{
		%print the coordinates of the entrance. It is associated with the entrances_coordinates.th file
		\edef\tmp{\the\ECoordinates} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thcoords: \ss\the\ECoordinates\par}
			\vskip0.5cm
		\fi
		%print cavelength and depth
		\everypar{\hangindent=2em\hangafter=1}
		\edef\tmp{\the\cavelength} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cavelengthtitle: \ss\the\cavelength\par}
		\fi
		\edef\tmp{\the\cavedepth} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cavedepthtitle: \ss\the\cavedepth\par}
		\fi
		# % end bruces addition

		%print explorers names
		\edef\tmp{\the\exploteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\explotitle: \ss\the\exploteam\quad\si\the\explodate\par}
		\fi
		%print surveyors names
		\edef\tmp{\the\topoteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\topotitle: \ss\the\topoteam\quad\si\the\topodate\par}
		\fi
		 %%print the guides
		\edef\tmp{\the\guide} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thguide: \ss\the\guide\par}
		\fi
		%print cartographers names
		\edef\tmp{\the\cartoteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cartotitle: \ss\the\cartoteam\quad\si\the\cartodate\par}
		\fi
		%print synthesys name !!!  !!! with newtoks\synth \synth={Synth Name} in the thconfig
		\edef\tmp{\the\synth} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thsynth: \ss\the\synth\par}
		\fi
		%print the club
		\edef\tmp{\the\club} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thclub: \ss\the\club\par}
		\fi
		%%print the expedition
		\edef\tmp{\the\expe} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thexpe: \ss\the\expe\par}
		\fi
        %%print the web page
		\edef\tmp{\the\wpage} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thwpage: \ss\the\wpage\par}
		\fi
		# % start bruces addition (compilation version and date modified to use built-in 5.3.15 variables)
		\edef\tmp{\the\thversion} \ifx\tmp\empty \else  %only write version and date if version is not emplty
			{\the\legendtextsize\si\the\thversiontitleA: \ss\the\thversiontitleB \ss\the\thversion}
		% \fi
		% \edef\tmp{\the\currentdate} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\datetitle \ss\the\currentdate\par}
		\fi

		# % end bruces addition
		%print copyrights
		\edef\tmp{\the\copyrights} \ifx\tmp\empty \else
			{\the\legendtextsize\ss\the\copyrights\par}
		\fi
		
		\bigskip
		\edef\tmp{\the\thanksto} \ifx\tmp\empty \else
				{\the\legendtextsize\si\the\ththanksto: \ss\the\thanksto\par}
				%\def\ththankstotitle{Nos remerciements : }
				%{\everypar{\hangindent=7.2em\hangafter=1}
				%\size[\thsizem]\si\ththankstotitle \ss\ththanksto\par}
		\fi
		}
		\formattedlegend
		\color[0 0 0]
		}
	endcode
endlayout


#------------------------------
layout header_coupe_vert-auto
#<en> Layout to change the header (extended elevation)
#     This code is experimental redefinition of map header
#     Bruce Mutton           Therion 5.3.15 make use of new variables
#	  Xavier Robert (2020/04/27)
#     Header specifically for extended elevation maps with a vertical scale bar 
#     located at the right of the header.
#<fr> Layout pour modifier le cartouche (header) de la projection en coupe développée
#     Ce code de redéfinition est expérimental experimental et basé sur le travail de
#     Bruce Mutton           Therion 5.3.15 fait appel à de nouvelles variables
#	  Xavier Robert (2020/04/27)
#     Header développé spécialement pour les coupes étendues et projetées, avec l'échelle
#     verticale et localisée à la droite du header.

	copy scalebar_vert

	#<en> This one affects maps only (extended view)
	#<fr> Ceci ne touche que les maps (coupes développées)
	code tex-map
		\legendcontent={%
			\hsize=\legendwidth
			\color[0 0 0]\the\legendtextcolor
			% print scalebar
			\ifscalebar\hskip1.3cm\vbox to 0pt{\line{\hfil\scalebar}\vss}\fi
			% print cave map name
			\edef\tmp{\the\cavename} \ifx\tmp\empty \else
				{\the\legendtextheadersize\the\cavename}\vskip0.5cm
			\fi
			% print comment
			{\rightskip=0pt plus 3em\parskip=3bp
			\edef\tmp{\the\comment} \ifx\tmp\empty \else
				{\the\legendtextsize\the\comment} \par\medskip\vskip0.3cm
			\fi}
		{
		%print the coordinates of the entrance. It is associated with the entrances_coordinates.th file
		\edef\tmp{\the\ECoordinates} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thcoords: \ss\the\ECoordinates\par}
			\vskip0.5cm
		\fi
		%print cavelength and depth
		\everypar{\hangindent=2em\hangafter=1}
		\edef\tmp{\the\cavelength} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cavelengthtitle: \ss\the\cavelength\par}
		\fi
		\edef\tmp{\the\cavedepth} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cavedepthtitle: \ss\the\cavedepth\par}
		\fi
		# % end bruces addition

		%print explorers names
		\edef\tmp{\the\exploteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\explotitle: \ss\the\exploteam\quad\si\the\explodate\par}
		\fi
		%print surveyors names
		\edef\tmp{\the\topoteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\topotitle: \ss\the\topoteam\quad\si\the\topodate\par}
		\fi
		 %%print the guides
		\edef\tmp{\the\guide} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thguide: \ss\the\guide\par}
		\fi
		%print cartographers names
		\edef\tmp{\the\cartoteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cartotitle: \ss\the\cartoteam\quad\si\the\cartodate\par}
		\fi
		%print synthesys name !!!  !!! with newtoks\synth \synth={Synth Name} in the thconfig
		\edef\tmp{\the\synth} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thsynth: \ss\the\synth\par}
		\fi
		%print the club
		\edef\tmp{\the\club} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thclub: \ss\the\club\par}
		\fi
		%%print the expedition
		\edef\tmp{\the\expe} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thexpe: \ss\the\expe\par}
		\fi
        %%print the web page
		\edef\tmp{\the\wpage} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thwpage: \ss\the\wpage\par}
		\fi
		# % start bruces addition (compilation version and date modified to use built-in 5.3.15 variables)
		\edef\tmp{\the\thversion} \ifx\tmp\empty \else  %only write version and date if version is not emplty
			{\the\legendtextsize\si\the\thversiontitleA: \ss\the\thversiontitleB \ss\the\thversion}
		% \fi
		% \edef\tmp{\the\currentdate} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\datetitle \ss\the\currentdate\par}
		\fi

		# % end bruces addition
		%print copyrights
		\edef\tmp{\the\copyrights} \ifx\tmp\empty \else
			{\the\legendtextsize\ss\the\copyrights\par}
		\fi
		
		\bigskip
		\edef\tmp{\the\thanksto} \ifx\tmp\empty \else
				{\the\legendtextsize\si\the\ththanksto: \ss\the\thanksto\par}
				%\def\ththankstotitle{Nos remerciements : }
				%{\everypar{\hangindent=7.2em\hangafter=1}
				%\size[\thsizem]\si\ththankstotitle \ss\ththanksto\par}
		\fi
		}
		\formattedlegend
		\color[0 0 0]
		}
	endcode
endlayout

#------------------------------
layout header_coupe
#<en> Layout to change the header (extended elevation)
#     This code is experimental redefinition of map header
#     Bruce Mutton           Therion 5.3.15 make use of new variables
#<fr> Layout pour modifier le cartouche (header) de la projection en coupe développée
#     Ce code de redéfinition est expérimental experimental et basé sur le travail de
#     Bruce Mutton           Therion 5.3.15 fait appel à de nouvelles variables

	copy scalebar_horiz

	#<en> This one affects maps only (extended view)
	#<fr> Ceci ne touche que les maps (coupes développées)
	code tex-map
		\legendcontent={%
			\hsize=\legendwidth
			\color[0 0 0]\the\legendtextcolor
			%\ifnortharrow\vbox to 0pt{\line{\hfil\northarrow}\vss}\fi
			%print cave map name
			\edef\tmp{\the\cavename} \ifx\tmp\empty \else
				{\the\legendtextheadersize\the\cavename}\vskip0.5cm
			\fi
			%print comment
			{\rightskip=0pt plus 3em\parskip=3bp
			\edef\tmp{\the\comment} \ifx\tmp\empty \else
				{\the\legendtextsize\the\comment} \par\medskip\vskip1cm
			\fi}
			%print scalebar
			\ifscalebar\scalebar\vskip1cm\fi
		{
		%print the coordinates of the entrance. It is associated with the entrances_coordinates.th file
		\edef\tmp{\the\ECoordinates} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thcoords: \ss\the\ECoordinates\par}
			\vskip0.5cm
		\fi
		%print cavelength and depth
		\everypar{\hangindent=2em\hangafter=1}
		\edef\tmp{\the\cavelength} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cavelengthtitle: \ss\the\cavelength\par}
		\fi
		\edef\tmp{\the\cavedepth} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cavedepthtitle: \ss\the\cavedepth\par}
		\fi
		# % end bruces addition

		%print explorers names
		\edef\tmp{\the\exploteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\explotitle: \ss\the\exploteam\quad\si\the\explodate\par}
		\fi
		%print surveyors names
		\edef\tmp{\the\topoteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\topotitle: \ss\the\topoteam\quad\si\the\topodate\par}
		\fi
		 %%print the guides
		\edef\tmp{\the\guide} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thguide: \ss\the\guide\par}
		\fi
		%print cartographers names
		\edef\tmp{\the\cartoteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cartotitle: \ss\the\cartoteam\quad\si\the\cartodate\par}
		\fi
		%print synthesys name !!!  !!! with newtoks\synth \synth={Synth Name} in the thconfig
		\edef\tmp{\the\synth} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thsynth: \ss\the\synth\par}
		\fi
		%print the club
		\edef\tmp{\the\club} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thclub: \ss\the\club\par}
		\fi
		%%print the expedition
		\edef\tmp{\the\expe} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thexpe: \ss\the\expe\par}
		\fi
        %%print the web page
		\edef\tmp{\the\wpage} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thwpage: \ss\the\wpage\par}
		\fi
		# % start bruces addition (compilation version and date modified to use built-in 5.3.15 variables)
		\edef\tmp{\the\thversion} \ifx\tmp\empty \else  %only write version and date if version is not emplty
			{\the\legendtextsize\si\the\thversiontitleA: \ss\the\thversiontitleB \ss\the\thversion}
		% \fi
		% \edef\tmp{\the\currentdate} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\datetitle \ss\the\currentdate\par}
		\fi

		# % end bruces addition
		%print copyrights
		\edef\tmp{\the\copyrights} \ifx\tmp\empty \else
			{\the\legendtextsize\ss\the\copyrights\par}
		\fi
		
		\bigskip
		\edef\tmp{\the\thanksto} \ifx\tmp\empty \else
				{\the\legendtextsize\si\the\ththanksto: \ss\the\thanksto\par}
				%\def\ththankstotitle{Nos remerciements : }
				%{\everypar{\hangindent=7.2em\hangafter=1}
				%\size[\thsizem]\si\ththankstotitle \ss\ththanksto\par}
		\fi
		}
		\formattedlegend
		\color[0 0 0]
		}
	endcode
endlayout

#------------------------------
layout headeratlas
#<en> Layout to change the header (plan projection)
#     This code is experimental redefinition of map header and based on the work of
#     Bruce Mutton           Therion 5.3.15 make use of new variables
#<fr> Layout pour modifier le cartouche (header) de la projection en plan
#     Ce code de redéfinition est expérimental experimental et basé sur le travail de
#     Bruce Mutton           Therion 5.3.15 fait appel à de nouvelles variables

	copy scalebar_horiz
	
	#<en> This one affects maps only
	#<fr> Ceci ne touche que les maps (plans)
	code tex-map
		\legendcontent={%
			\hsize=\legendwidth
			\color[0 0 0]\the\legendtextcolor
			\ifnortharrow\vbox to 0pt{\line{\hfil\northarrow}\vss}\fi
			%print cave map name
			\edef\tmp{\the\cavename} \ifx\tmp\empty \else
				{\the\legendtextheadersize\the\cavename}\vskip0.5cm
			\fi
			%print comment
			{\rightskip=0pt plus 3em\parskip=3bp
			\edef\tmp{\the\comment} \ifx\tmp\empty \else
				{\the\legendtextsize\the\comment} \par\medskip\vskip1cm
			\fi}
			%print scalebar
			\ifscalebar\scalebar\vskip1cm\fi
		%print entrances coordinates (Lat-Long/WGS84) if defined	
		\edef\tmp{\the\ECoordinates} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thcoords: \ss\the\ECoordinates\par}
			\vskip0.5cm
		\fi

		% start bruces addition
		# %    CS
		\edef\tmp{\the\outcsname} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thproj: \ss\the\outcsname\par}
		\fi
		\edef\tmp{\the\northdir} \ifx\tmp\empty \else
			{\the\legendtextsize\ss\the\northdir north }
		\fi
		\edef\tmp{\the\magdecl} \ifx\tmp\empty \else
			{\the\legendtextsize\ss\the\magdecl deg \par}
		\fi
		\vskip0.5cm
		% end bruces addition
		#%print comment
		{
		#\rightskip=0pt plus 3em\parskip=3bp
		#\edef\tmp{\the\comment} \ifx\tmp\empty \else
		#	{\the\legendtextsize\the\comment} \par\medskip
		#\fi
		%print cavelength and depth
		\everypar{\hangindent=2em\hangafter=1}
		\edef\tmp{\the\cavelength} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cavelengthtitle: \ss\the\cavelength\par}
		\fi
		\edef\tmp{\the\cavedepth} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cavedepthtitle: \ss\the\cavedepth\par}
		\fi
		# % start bruces addition
		## %      altitude
		#\edef\tmp{\the\cavemaxz} \ifx\tmp\empty \else
		#	{\the\legendtextsize\si\the\depthrangetitle \ss\the\cavemaxz m to}
		#\fi
		#\edef\tmp{\the\caveminz} \ifx\tmp\empty \else
		#	{\the\legendtextsize\ss\the\caveminz m \par} %above mean sea level
		#\fi
		# % end bruces addition

		%print explorers names
		\edef\tmp{\the\exploteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\explotitle: \ss\the\exploteam\quad\si\the\explodate\par}
		\fi
		%print surveyors names
		\edef\tmp{\the\topoteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\topotitle: \ss\the\topoteam\quad\si\the\topodate\par}
		\fi
		 %%print the guides
		\edef\tmp{\the\guide} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thguide: \ss\the\guide\par}
		\fi
		%print cartographers names
		\edef\tmp{\the\cartoteam} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\cartotitle: \ss\the\cartoteam\quad\si\the\cartodate\par}
		\fi
		%print synthesys name !!!  !!! with newtoks\synth \synth={Synth Name} in the thconfig
		\edef\tmp{\the\synth} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thsynth: \ss\the\synth\par}
		\fi
		%print the club
		\edef\tmp{\the\club} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thclub: \ss\the\club\par}
		\fi
		%%print the expedition
		\edef\tmp{\the\expe} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thexpe: \ss\the\expe\par}
		\fi
        %%print the web page
		\edef\tmp{\the\wpage} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\thwpage: \ss\the\wpage\par}
		\fi
		# % start bruces addition (compilation version and date modified to use built-in 5.3.15 variables)
		\edef\tmp{\the\thversion} \ifx\tmp\empty \else  %only write version and date if version is not emplty
			{\the\legendtextsize\si\the\thversiontitleA: \ss\the\thversiontitleB \ss\the\thversion}
		% \fi
		% \edef\tmp{\the\currentdate} \ifx\tmp\empty \else
			{\the\legendtextsize\si\the\datetitle \ss\the\currentdate\par}
		\fi

		# % end bruces addition
		%print copyrights
		\edef\tmp{\the\copyrights} \ifx\tmp\empty \else
			{\the\legendtextsize\ss\the\copyrights\par}
		\fi
		
		\bigskip
		\edef\tmp{\the\thanksto} \ifx\tmp\empty \else
				{\the\legendtextsize\si\the\ththanksto: \ss\the\thanksto\par}
				%\def\ththankstotitle{Nos remerciements : }
				%{\everypar{\hangindent=7.2em\hangafter=1}
				%\size[\thsizem]\si\ththankstotitle \ss\ththanksto\par}
		\fi
		}
		\formattedlegend
		\color[0 0 0]
		}

	endcode
endlayout


#------------------------------
layout layoutmapborder
#<en> If you want to draw a frame around the map
#<fr> Si vous voulez un cadre autour de votre topographie
	code tex-map
		\framethickness=0.5mm
	endcode
endlayout


#<en> CODE TO CUSTOMISE ATLAS OUTPUT
#<fr> CODE POUR CUSTOMISER L'ATLAS
#----------------------------------
layout LayoutAtlasNorthArrow2
#<en> This code is a redefinition of the default atlas definition
#     that includes both north arrow & scale bar beside the navigation pane
#     from Bruce Mutton (2019/08)
#<fr> Ce code est une redéfinition de la définition par défaut de l'Altlas
#     Cela inclus à la fois la flèche du nord et la barre d'échelle du panneau de navigation.
#     from Bruce Mutton (2019/08)

	code tex-atlas
		\def\dopage{%
			\vbox{\centerline{\framed{\mapbox}}
				\bigskip
				\line{%
					\vbox to \ht\navbox{
						\hbox{\size[20]\the\pagelabel
						\ifpagenumbering\space(\the\pagenum)\fi
						\space\size[16]\the\pagename}
						\ifpagenumbering
							\medskip
							\hbox{\qquad\qquad
								\vtop{%
									\hbox to 0pt{\hss\showpointer\pointerN\hss}
									\hbox to 0pt{\llap{\showpointer\pointerW\hskip0.7em}%
									\raise1pt\hbox to 0pt{\hss$\updownarrow$\hss}%
									\raise1pt\hbox to 0pt{\hss$\leftrightarrow$\hss}%
									\rlap{\hskip0.7em\showpointer\pointerE}}
									\hbox to 0pt{\hss\showpointer\pointerS\hss}
								}\qquad\qquad
								\vtop{
									\def\arr{$\uparrow$}
									\showpointerlist\pointerU
									\def\arr{$\downarrow$}
									\showpointerlist\pointerD
								}
							}
						\fi
						\vss
					}
					\hss
					\vbox to \ht\navbox{
						\ifnortharrow\hbox to 0pt{\hss\northarrow\qquad}\fi
						\vss
						\ifscalebar\hbox to 0pt{\hss\scalebar\qquad}\fi
					}
					\box\navbox
				}
			}
		}

endlayout LayoutAtlasNorthArrow2


layout LayoutAtlasNorthArrow
#<en> Layout for the set of the Atlas North Arrow to override 
#     the north arrow definition of the layout drawingconfig
#     and use a smaller North arrow to avoid overlaps with the scale bar
#     For that, it should be call first in the layout Altas of the .thconfig file.
#<fr> Layout pour définir le set up de l'Atlas North Arrow.
#     pour effacer la définition de la flèche du nord du layout drawingconfig
#     et éviter la superposition de la flèche avec la barre d'échelle.
#     Pour cela, il convient de placer l'appel à ce Layout avant tous les autres layouts
#     dans le layout Atlas du .thconfig
	code metapost
		def s_northarrow (expr rot) =
			begingroup
				#interim defaultscale:=0.7; % scale your north arrow here
				interim defaultscale:=0.5; % scale your north arrow here; 0.5 is the best value for atlas
				T:=identity scaled defaultscale rotated -rot;
				interim linecap:=squared;
				interim linejoin:=rounded;
				thfill (-.5cm,-.1cm)--(0,2.5cm)--(.5cm,-.1cm)--cycle;
				pickup pencircle scaled (0.08cm * defaultscale);
				thdraw (0,0)--(0,-2.5cm);
				pickup pencircle scaled (0.16cm * defaultscale);
				p:=(0.4cm,0.6cm);
				thdraw ((p--(p yscaled -1)--(p xscaled -1)--(p scaled -1)) shifted (0,-1.0cm));
				label.rt(thTEX("mg") scaled 1.6, (.6cm,-1.6cm)) transformed T;
			endgroup;
		enddef;
	endcode
		
endlayout LayoutAtlasNorthArrow


layout AtlasSetUp
#<en> Layout for the set of the Atlas
#<fr> Layout pour définir le set up de l'Atlas
	
	#<en> "size" are the dimensions of the square/rectangle which will be
	#     occupied by part of the survey corresponding to each smal inset.
	#     15 x 20, is good to print with an A4-paper.
	#<fr> "size", c'est pour l'atlas. Ce sont les dimensions du carré dont
	#     l'interieur sera occupé par la partie de la topo correspondante à
	#     chaque une des pagines. 15 x 20, ça va bien pour imprimer A4.
	size 15 20 cm

	#<en> In the atlas, we choose an overlap of 1 cm with the neibourghood pages
	#<fr> Dans l'atlas, on va superposer 1 cm de chaque page voisine
	overlap 1 cm

	#<en> "page-setup".
	#     We specify 1) the dimensions of the paper: 21 X 29.7 (A4)
	#     2) the surface usable to print, here 17 X 28.2
	#     and then 3, we can add a 3 cm left margin (21 - 17 -1 = 3)
	#     and a 1.5 cm top margin (29.7 - 27.2 - 1 = 1,5)
	#<fr> "page-setup", ça sert pour le map et pour l'atlas aussi.
	#     on spécifie les dimensions de la feuille de papier : 21 X 29,7 (A4)
	#     la surface imprimible du papier, ce sont 17 X 28,2
	#     Alors, on peut indiquer une marge à gauche de 3 (21-17-1=3)
	#     et une marge en haut de 1,5 (29,7-27,2-1=1,5)
	#     en centimetres  
	page-setup 21 29.7 17 27.2 3 1.5 cm  
	
	#<en> Print (or not) the title of the pages before each capter of the Atlas
	#<fr> Affiche (ou non) le titre des pages avant chaque chapitre de l’atlas
	title-pages on
	
	#<en> Zoom factor of the navigation pannel; by default, 30
	#<fr> Facteur de zoom du panneau de navigation ; Par défault, 30
	nav-factor 30
	
	#<en> Define the number of pages in the 2 directions of the navigation pannel
	#<fr> Définir le nombre de pages de l'atlas dans les 2 directions du panneau de navigation
	nav-size 2 2
	
	
	code tex-atlas
		\atlastitlepages
		\insertmaps
		\formattedlegend

endlayout AtlasSetUp


#------------------------------
layout layoutcontinuation
#<en> If you want to write all the texts that go with continuations marks
#<fr> Si vous voulez écrire sur la carte le texte qui est donnée dans chaque définition 
#     de point d'interrogation de continuation

	code metapost
		def p_continuation(expr pos,theta,sc,al) =
			% draw default continuation symbol
			p_continuation_UIS(pos,theta,sc,al);
			% if text attribute is set
			if known(ATTR__text) and picture(ATTR__text):
				% set labeling color to light orange
				push_label_fill_color(1.0, 0.9, 0.8);
				% draw filled label with text next to ?
				p_label.urt(ATTR__text,(.5u,-.25u) transformed T,0.0,8);
				% restore original labeling color
				pop_label_fill_color;
			fi;
		enddef;
	endcode
	
endlayout layoutcontinuation


#------------------------------
layout northarrowMG
#<en> New Northarrow definition
#<fr> Nouvelle définition de la flèche du nord

	code metapost
	  	# If you want to get both, magnetic and geographic north,
  		# with \cartodate ?
		def s_northarrow (expr rot) =
			%valscal=1.2; % scale your north arrow here
			valscal=0.7; % scale your north arrow here
			decl:=MagDecl; % set the magnetic declination
			T:=identity;
			picture tmp_pic;
			tmp_pic = image (
				pickup pencircle scaled .3;
				thfill fullcircle scaled 4cm withcolor 1white;
				thdraw fullcircle scaled 3.1cm;
				thdraw fullcircle scaled 4.05cm;
				pickup pencircle scaled .1;
				thdraw fullcircle scaled 3cm;
				thdraw fullcircle scaled 4cm;
				pickup pencircle scaled .2;
				thdraw (dir(45)*2.025cm)--(dir(45)*3.7cm);
				thdraw (dir(135)*2.025cm)--(dir(135)*3.7cm);
				thdraw (dir(225)*2.025cm)--(dir(225)*3.7cm);
				thdraw (dir(315)*2.025cm)--(dir(315)*3.7cm);
				pickup pencircle scaled .1;
				for whereto=0 step 15 until 345:
					thdraw dir(whereto)*.65cm--dir(whereto)*.9cm;
					thdraw dir(whereto)*1.4cm--dir(whereto)*1.5cm;
				endfor;
				for whereto=0 step 5 until 355:
					thdraw dir(whereto)*.65cm--dir(whereto)*.8cm;
					thdraw dir(whereto)*1.45cm--dir(whereto)*1.5cm;
				endfor;
				for whereto=0 step 1 until 359:
					thdraw dir(whereto)*1.94cm--dir(whereto)*2cm;
				endfor;
				pickup pencircle scaled 1;
				thdraw fullcircle scaled 1cm;
				thdraw fullcircle scaled 1.1cm;
				thdraw fullcircle scaled 1.3cm withpen pencircle scaled .3;
				vald=90-decl;
				texrot=0-decl;
				drawarrow(dir(vald)*-2cm--dir(vald)*2cm) withpen pencircle scaled .2;
				% Add the date of the last drawing
				thdraw image(label.top(btex $mg$ etex, (0,0)) scaled .5 rotated texrot;) shifted (dir(vald)*2.04cm);
				thfill (1.06cm,1.06cm)--(0,.2cm)--(-1.06cm,1.06cm)--(-.2cm,0)--(-1.06cm,-1.06cm)--(0,-.2cm)--(1.06cm,-1.06cm)--(.2cm,0)--cycle;
				thfill (-.2cm,.2cm)--(0,2cm)--(0,0)--cycle;
				thfill (.2cm,-.2cm)--(0,-2cm)--(0,0)--cycle;
				thfill (.2cm,.2cm)--(2cm,0)--(0,0)--cycle;
				thfill (-.2cm,-.2cm)--(-2cm,0)--(0,0)--cycle;
				thfill (.2cm,.2cm)--(-0,2cm)--(0,0)--cycle withcolor 1white;
				thfill (.2cm,-.2cm)--(2cm,0)--(0,0)--cycle withcolor 1white;
				thfill (-.2cm,-.2cm)--(0,-2cm)--(0,0)--cycle withcolor 1white;
				thfill (-.2cm,.2cm)--(-2cm,0)--(0,0)--cycle withcolor 1white;
				pickup pencircle scaled .2;
				thdraw (-.2cm,.2cm)--(0,2cm)--(.2cm,.2cm)--(2cm,0cm)--(.2cm,-.2cm)--(0,-2cm)--(-.2cm,-.2cm)--(-2cm,0)--cycle;
				thfill fullcircle scaled .56cm withcolor 1white;
				pickup pencircle scaled .1;
				thdraw (.28cm,0)..(0,.28cm)..(-.28cm,0)..(0,-.28cm)..cycle;
				pickup pencircle scaled .4;
				thdraw (.2cm,0)..(0,.2cm)..(-.2cm,0)..(0,-.2cm)..cycle;
				label.bot(btex $N$ etex, (0,2.6cm));
				label.lft(btex $E$ etex, (2.6cm,0));
				label.rt(btex $W$ etex, (-2.6cm,0));
				label.top(btex $S$ etex, (0,-2.6cm));
			);
			thdraw tmp_pic scaled valscal rotatedaround(origin, -rot);
		enddef;
	endcode
endlayout northarrowMG


#___________________________________________
layout test
#<en> A test layout to test you new symbols, configurations,... ;-)
#<fr> Un layout de test pour tester vos nouveaux symboles, configurations,... ;-)

	code metapost

		def p_u_prof (expr P,R,S,A)=
			T:=identity aligned A rotated R scaled S shifted P;
			pickup PenD;
			p:=(-.3u,0)--(.3u,0);
			thdraw p; 
			#thdraw p rotated 90;
			p:=fullcircle scaled .2u;
			#thclean p; 
			thdraw p;
		enddef;
		vardef p_label@#(expr txt,P,R,mode) =
			if mode=1:
				thdrawoptions(withcolor .8red + .4blue);
#				thdrawoptions(withcolor .8red + .6blue);
				p_u_prof(P);
				% append "m" to label
				picture txtm;
				% calcul profondeur
				%numeric profondeur;
				profondeur:=(\thaltitude-\cavemaxz);
				picture txtprofondeur;
				txtm:=image(
					draw txt;
					interim labeloffset:=0;
					#label.urt(btex \thaltitude m etex, lrcorner txt);
					label.urt(btex profondeur m etex, lrcorner txt);
					%label.urt(btex \thdepth m etex, lrcorner txt);
				);
				% give extra offset in case of l/r/t/b alignment
				pair ctmp;
				ctmp:=center thelabel@#("x", (0,0));
				if (xpart ctmp * ypart ctmp)=0:
					interim labeloffset:=(.4u);
				else: % diagonal alignment
					interim labeloffset:=(.2u);
				fi;
				% draw label
				lab:=thelabel@#(txtm, P);
				draw lab _thop_; % use color
				thdrawoptions();
				bboxmargin:=0.8bp;
				write_circ_bbox((bbox lab) smoothed 2);
			else:
				if mode=7: interim labeloffset:=(u/8) fi;
				lab:=thelabel@#(txt, P);
				if mode>1: pickup PenD fi;
				if mode=2: process_uplabel;
				elseif mode=3: process_downlabel;
				elseif mode=4: process_updownlabel;
				elseif mode=5: process_circledlabel;
				elseif mode=6: process_boxedlabel;
				elseif mode=7: process_label(P,R);  % station name
				elseif mode=8: process_filledlabel(P, R);
				else: process_label(P,R); fi;
	    	fi;
 		enddef;

	endcode

endlayout