Index: tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/WordAnnotationToolbar.java
===================================================================
--- tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/WordAnnotationToolbar.java	(revision 1618)
+++ tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/WordAnnotationToolbar.java	(revision 1619)
@@ -18,6 +18,7 @@
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.TableViewerColumn;
 import org.eclipse.jface.viewers.ViewerCell;
@@ -256,6 +257,7 @@
 			@Override
 			public void run() {
 				try {
+					annotationColumn.setText("*"+typesList.get(0).getName());
 					editor.refresh(false);
 				} catch (Exception e) {
 					// TODO Auto-generated catch block
@@ -293,6 +295,7 @@
 			@Override
 			public void run() {
 				try {
+					annotationColumn.setText("*"+typesList.get(0).getName());
 					editor.refresh(false);
 				} catch (Exception e) {
 					// TODO Auto-generated catch block
@@ -465,6 +468,14 @@
 					String name = annotationTypesCombo.getCombo().getText();
 					if (currentKnowledgeRepository.getType(name) == null) {
 						createNewType(e, name);
+					} else {
+						for (AnnotationType type : typesList) {
+							if (name.equals(type.getId())) {
+								StructuredSelection selection = new StructuredSelection(type);
+								annotationTypesCombo.setSelection(selection, true);
+								break;
+							}
+						}
 					}
 				}
 			}
@@ -485,30 +496,7 @@
 		annotationTypesCombo.addSelectionChangedListener(new ISelectionChangedListener() {
 			@Override
 			public void selectionChanged(SelectionChangedEvent event) {
-				IStructuredSelection sel = (IStructuredSelection) annotationTypesCombo.getSelection();
-				AnnotationType type = (AnnotationType) sel.getFirstElement();
-				if (type == null) return;
-				if (type.getSize() != AnnotationType.ValuesSize.LARGE) {
-					try {
-						KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
-						typeValuesList = kr.getValues(type);
-					} catch (Exception e) {
-						// TODO Auto-generated catch block
-						e.printStackTrace();
-					}
-				}
-
-				annotationColumn.setText(type.getName());
-				annotations.setViewAnnotation(type);
-				annotations.setAnnotationOverlap(true);
-				try {
-					editor.refresh(false);
-				} catch (Exception e) {
-					// TODO Auto-generated catch block
-					e.printStackTrace();
-				}
-
-				updateAnnotationWidgetStates();
+				onAnnotationTypeSelected(event);
 			}
 		});
 
@@ -620,6 +608,34 @@
 		return true;
 	}
 
+	protected void onAnnotationTypeSelected(SelectionChangedEvent event) {
+		IStructuredSelection sel = (IStructuredSelection) annotationTypesCombo.getSelection();
+		AnnotationType type = (AnnotationType) sel.getFirstElement();
+		if (type == null) return;
+		
+		if (type.getSize() != AnnotationType.ValuesSize.LARGE) {
+			try {
+				KnowledgeRepository kr = KnowledgeRepositoryManager.getKnowledgeRepository(type.getKnowledgeRepository());
+				typeValuesList = kr.getValues(type);
+			} catch (Exception e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+
+		annotationColumn.setText(type.getName());
+		annotations.setViewAnnotation(type);
+		annotations.setAnnotationOverlap(true);
+		try {
+			editor.refresh(false);
+		} catch (Exception e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+
+		updateAnnotationWidgetStates();
+	}
+
 	protected void createNewType(TypedEvent e, String typeName) {
 		
 		if (currentKnowledgeRepository == null) return;
@@ -640,28 +656,33 @@
 			AnnotationType type = kr.addType(name, id, ""); //$NON-NLS-1$
 			type.setEffect(AnnotationEffect.TOKEN);
 			typesList.add(type);
+			annotationTypesCombo.refresh();
+			StructuredSelection selection = new StructuredSelection(type);
+			annotationTypesCombo.setSelection(selection, true);
 
-			if (annotationTypesCombo != null) annotationTypesCombo.refresh();
-			if (typesList.size() == 1) {
-				if (annotationTypesCombo != null) annotationTypesCombo.getCombo().select(0);
-				annotations.setViewAnnotation(type);
-				annotations.setAnnotationOverlap(true);
-				try {
-					editor.refresh(false);
-				} catch (Exception e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-				annotationArea.layout(true);
-			} else {
-				if (typesList.size() > 1) {
-					if (annotationTypesCombo != null) {
-						annotationTypesCombo.getCombo().select(typesList.size()-1);
-					}
-				}
-			}
-			KRView.refresh();
-			updateAnnotationWidgetStates();
+//			if (annotationTypesCombo != null) annotationTypesCombo.refresh();
+//			if (typesList.size() == 1) {
+//				if (annotationTypesCombo != null) annotationTypesCombo.getCombo().select(0);
+//				annotations.setViewAnnotation(type);
+//				annotations.setAnnotationOverlap(true);
+//				try {
+//					editor.refresh(false);
+//				} catch (Exception e1) {
+//					// TODO Auto-generated catch block
+//					e1.printStackTrace();
+//				}
+//				annotationArea.layout(true);
+//			} else {
+//				if (typesList.size() > 1) {
+//					if (annotationTypesCombo != null) {
+//						annotationTypesCombo.getCombo().select(typesList.size()-1);
+//					}
+//				}
+//			}
+//			KRView.refresh();
+//			updateAnnotationWidgetStates();
+			
+			//onAnnotationTypeSelected(null);
 		} else {
 			System.out.println("Creation aborted."); //$NON-NLS-1$
 		}
@@ -686,6 +707,7 @@
 			ex.printStackTrace();
 			return false;
 		}
+		annotationColumn.setText(typesList.get(0).getName());
 		return true;
 	}
 
Index: tmp/org.txm.groovy.core/src/java/org/txm/groovy/core/GroovyScriptedImportEngine.java
===================================================================
--- tmp/org.txm.groovy.core/src/java/org/txm/groovy/core/GroovyScriptedImportEngine.java	(revision 1618)
+++ tmp/org.txm.groovy.core/src/java/org/txm/groovy/core/GroovyScriptedImportEngine.java	(revision 1619)
@@ -130,7 +130,9 @@
 				Boolean readyToLoad = (Boolean)ready;
 				//System.out.println("TRY TO LOAD THE BINARY CORPUS CREATED: "+basedir);
 				if (readyToLoad) {
-//					
+					
+					project.saveParameters(true);
+					
 					Log.info(GroovyMessages.restartingToolboxSearchengines);
 					Toolbox.getEngineManager(EngineType.SEARCH).restartEngines();
 					Log.info(TXMCoreMessages.common_done);
Index: tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZPager.groovy
===================================================================
--- tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZPager.groovy	(revision 1618)
+++ tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZPager.groovy	(revision 1619)
@@ -124,6 +124,7 @@
 				}
 			} catch(Exception e) {
 				println "Error: could not create $txmFile 'default' edition: "+e
+				e.printStackTrace()
 			}
 		}
 
Index: tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZDefaultPagerStep.groovy
===================================================================
--- tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZDefaultPagerStep.groovy	(revision 1618)
+++ tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZDefaultPagerStep.groovy	(revision 1619)
@@ -92,7 +92,7 @@
 	def noteElements = new HashSet<String>();
 	def outOfTextElements = new HashSet<String>();
 	XTZPager pager;
-	
+
 	/**
 	 * Instantiates a new pager.
 	 *
@@ -122,16 +122,16 @@
 		inputData = new BufferedInputStream(url.openStream());
 		factory = XMLInputFactory.newInstance();
 		parser = factory.createXMLStreamReader(inputData);
-		
+
 		String notesListString = pager.getImportModule().getProject().getTextualPlan("Note")
 		if (notesListString != null) for (def s : notesListString.split(",")) noteElements << s;
-		
+
 		String elems = pager.getImportModule().getProject().getTextualPlan("OutSideTextTagsAndKeepContent")
 		if (elems != null) for (def s : elems.split(",")) outOfTextElements << s;
-		
+
 		//process();
 	}
-	
+
 	public String getAttributeValue(def parser, String ns, String name) {
 		for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
 			if (name == parser.getAttributeLocalName(i)) {
@@ -144,7 +144,11 @@
 	private def closeMultiWriter() {
 		if (pagedWriter != null) {
 			def tags = pagedWriter.getTagStack().clone();
-
+//			println "STACK="+pagedWriter.getTagStack()
+//			def stack = Thread.currentThread().getStackTrace();
+//			int m = Math.min(15, stack.size()-1)
+//			for (def s : stack[1..m]) println s
+//			println "FILE ="+outfile
 			if (firstWord) { // there was no words
 				pagedWriter.writeCharacters("");
 				this.idxstart.add("${wordTag}_0")
@@ -152,7 +156,7 @@
 				//				}
 			}
 			pagedWriter.writeEndElements();
-
+			// write notes
 			if (notes.size() > 0) {
 				pagedWriter.writeEmptyElement("hr", ["id":"notes", "width":"20%", "align":"left"]);
 				//pagedWriter.writeStartElement("ol");
@@ -166,14 +170,24 @@
 					pagedWriter.writeEndElement() // </a>
 					pagedWriter.writeCharacters(note)
 					pagedWriter.writeEmptyElement("br")
-					//pagedWriter.writeEndElement() // </li>
 					i++;
 				}
-				//pagedWriter.writeEndElement() // </ol>
 				notes.clear()
 			}
 
 			pagedWriter.close();
+			
+//			println "STACK TO REWRITE: $tags"
+			for (int i = 0 ; i < tags.size() ; i++) {
+				String tag = tags.remove(0)
+				i--
+//				println "	tag=$tag"
+				if (tag == "div") {
+					break; // remove elements until first "div" tag
+				}
+			}
+//			println "STACK TO REWRITE2: $tags"
+			
 			return tags;
 		} else {
 			return [];
@@ -188,18 +202,9 @@
 	private boolean createNextOutput() {
 		wordcount = 0;
 		try {
-
 			def tags = closeMultiWriter();
-			for (int i = 0 ; i < tags.size() ; i++) {
-				String tag = tags[i]
-				if ("div" != tag) {
-					tags.remove(i--)
-				} else {
-					tags.remove(i--) // remove first "div"
-					break; // remove elements until first "div" tag
-				}
-			}
-			File outfile = new File(outdir, txtname+"_"+(++pagecount)+".html")
+			
+			outfile = new File(outdir, txtname+"_"+(++pagecount)+".html")
 			pages.add(outfile);
 			firstWord = true; // waiting for next word
 
@@ -222,6 +227,7 @@
 			pagedWriter.writeCharacters("\n")
 			pagedWriter.writeStartElement("body") //<body>
 			pagedWriter.writeStartElement("div", ["class": "txmeditionpage"]) //<div>
+//			println "OPENING: $tags"
 			pagedWriter.writeStartElements(tags);
 			return true;
 		} catch (Exception e) {
@@ -282,284 +288,300 @@
 	 * Process.
 	 */
 	public boolean process() {
-		boolean flagNote = false;
-		String noteContent = "";
-		String rend = ""
-		goToText();
 
-		String localname = "";
-		createNextOutput();
+		try {
+			boolean flagNote = false;
+			String noteContent = "";
+			String rend = ""
+			goToText();
 
-		for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
-			rend = "";
-			switch (event) {
-				case XMLStreamConstants.START_ELEMENT:
-					localname = parser.getLocalName();
-					if (outOfTextElements.contains(localname)) {
-						currentOutOfTextElements << localname
-						writeOutOfTextToEditText = true;
-					} else if (currentOutOfTextElements.size() > 0) {
-						currentOutOfTextElements << localname
-					}			
-					
-					if (localname == paginationElement) {
-						createNextOutput();
-						wordcount=0;
-						pagedWriter.write("\n");
-						if (getAttributeValue(parser, null,"n") != null) {
-							pagedWriter.writeElement("p", ["class":"txmeditionpb", "align":"center"], getAttributeValue(parser, null,"n"))
+			String localname = "";
+			if (!createNextOutput()) {
+				return false;
+			}
+
+			for (int event = parser.next(); event != XMLStreamConstants.END_DOCUMENT; event = parser.next()) {
+				rend = "";
+				switch (event) {
+					case XMLStreamConstants.START_ELEMENT:
+						localname = parser.getLocalName();
+						if (outOfTextElements.contains(localname)) {
+							currentOutOfTextElements << localname
+							writeOutOfTextToEditText = true;
+						} else if (currentOutOfTextElements.size() > 0) {
+							currentOutOfTextElements << localname
 						}
-					}
-					
-					rend = getAttributeValue(parser, null, "rend")
-					if (rend == null) rend = "";
-					switch (localname) {
-						case "text":
-							LinkedHashMap attributes = new LinkedHashMap();
-							for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
-								attributes[parser.getAttributeLocalName(i)] = parser.getAttributeValue(i).toString()
-							}
-							
+
+						if (localname == paginationElement) {
+							createNextOutput();
+							wordcount=0;
 							pagedWriter.write("\n");
-							pagedWriter.writeStartElement("p")
-							pagedWriter.writeAttribute("class", rend);
-							if (attributes.containsKey("id")) {
-								pagedWriter.writeElement("h3", attributes["id"])
+							if (getAttributeValue(parser, null,"n") != null) {
+								pagedWriter.writeElement("p", ["class":"txmeditionpb", "align":"center"], getAttributeValue(parser, null,"n"))
 							}
+						}
 
-							pagedWriter.writeStartElement("table");
-							for (String k : attributes.keySet()) {
-								if (k == "id") continue;
-								if (k == "rend") continue;
+						rend = getAttributeValue(parser, null, "rend")
+						if (rend == null) rend = "";
+						switch (localname) {
+							case "text":
+								LinkedHashMap attributes = new LinkedHashMap();
+								for (int i = 0 ; i < parser.getAttributeCount() ; i++) {
+									attributes[parser.getAttributeLocalName(i)] = parser.getAttributeValue(i).toString()
+								}
 
-								pagedWriter.writeStartElement("tr");
-								pagedWriter.writeElement("td", k);
-								pagedWriter.writeElement("td", attributes[k]);
-								pagedWriter.writeEndElement();
-							}
-							pagedWriter.writeEndElement() // table
-							pagedWriter.writeEndElement() // p
-							pagedWriter.writeCharacters("");
-							break;
-						case "ref":
-							pagedWriter.writeStartElement("a")
-							pagedWriter.writeAttribute("href", getAttributeValue(parser, null, "target"));
-							pagedWriter.writeAttribute("target", "_blank");
-							pagedWriter.writeAttribute("class", rend);
-							break;
-						case "head":
-							pagedWriter.write("\n");
-							pagedWriter.writeStartElement("h2", ["class":rend])
-							break;
-						case "graphic":
-							pagedWriter.write("\n");
-							String url = getAttributeValue(parser, null, "url")
-							if (url != null) {
-								// TEI <graphic rend="left-image" url="image.png"/> -> <center class="left-image"><img href="image.png"/></center> + <moncorpus>.css avec rule ".left-image"
-								pagedWriter.writeStartElement("center", ["class":rend]) // css -> .<rend> { ... } styles OR
-								pagedWriter.writeEmptyElement("img", ["src":url, "align":"middle"])
-								pagedWriter.writeEndElement() // div
-							}
-							break;
-						case "table":
-							pagedWriter.writeStartElement("table", ["class":rend])
-							pagedWriter.write("\n");
-							break;
-						case "row":
-							pagedWriter.writeStartElement("tr", ["class":rend])
-							break;
-						case "cell":
-							pagedWriter.writeStartElement("td", ["class":rend])
-							break;
-						case "list":
-							String type = getAttributeValue(parser, null,"type");
-							if ("unordered" == type) {
-								pagedWriter.writeStartElement("ul", ["class":rend])
-							} else {
-								pagedWriter.writeStartElement("ol", ["class":rend])
-							}
-							break
-						case "item":
-							pagedWriter.writeStartElement("li", ["class":rend])
-							break;
-						case "hi":
-						case "emph":
-							if ("i".equals(rend) || "italic".equals(rend)) {
-								pagedWriter.writeStartElement("i", ["class":rend])
-							} else if ("b".equals(rend) || "bold".equals(rend)) {
-								pagedWriter.writeStartElement("b", ["class":rend])
-							} else {
-								if ("emph".equals(localname)) {
+								pagedWriter.write("\n");
+								pagedWriter.writeStartElement("p")
+								pagedWriter.writeAttribute("class", rend);
+								if (attributes.containsKey("id")) {
+									pagedWriter.writeElement("h3", attributes["id"])
+								}
+
+								pagedWriter.writeStartElement("table");
+								for (String k : attributes.keySet()) {
+									if (k == "id") continue;
+									if (k == "rend") continue;
+
+									pagedWriter.writeStartElement("tr");
+									pagedWriter.writeElement("td", k);
+									pagedWriter.writeElement("td", attributes[k]);
+									pagedWriter.writeEndElement(); //tr
+								}
+								pagedWriter.writeEndElement() // table
+								pagedWriter.writeEndElement() // p
+								pagedWriter.writeCharacters("\n");
+								break;
+							case "ref":
+								pagedWriter.writeStartElement("a")
+								pagedWriter.writeAttribute("href", getAttributeValue(parser, null, "target"));
+								pagedWriter.writeAttribute("target", "_blank");
+								pagedWriter.writeAttribute("class", rend);
+								break;
+							case "head":
+								pagedWriter.write("\n");
+								pagedWriter.writeStartElement("h2", ["class":rend])
+								break;
+							case "graphic":
+								pagedWriter.write("\n");
+								String url = getAttributeValue(parser, null, "url")
+								if (url != null) {
+									// TEI <graphic rend="left-image" url="image.png"/> -> <center class="left-image"><img href="image.png"/></center> + <moncorpus>.css avec rule ".left-image"
+									pagedWriter.writeStartElement("center", ["class":rend]) // css -> .<rend> { ... } styles OR
+									pagedWriter.writeEmptyElement("img", ["src":url, "align":"middle"])
+									pagedWriter.writeEndElement() // center
+								}
+								break;
+							case "table":
+								pagedWriter.writeStartElement("table", ["class":rend])
+								pagedWriter.write("\n");
+								break;
+							case "row":
+								pagedWriter.writeStartElement("tr", ["class":rend])
+								break;
+							case "cell":
+								pagedWriter.writeStartElement("td", ["class":rend])
+								break;
+							case "list":
+								String type = getAttributeValue(parser, null,"type");
+								if ("unordered" == type) {
+									pagedWriter.writeStartElement("ul", ["class":rend])
+								} else {
+									pagedWriter.writeStartElement("ol", ["class":rend])
+								}
+								break
+							case "item":
+								pagedWriter.writeStartElement("li", ["class":rend])
+								break;
+							case "hi":
+							case "emph":
+								if ("i".equals(rend) || "italic".equals(rend)) {
 									pagedWriter.writeStartElement("i", ["class":rend])
-								} else { // hi
+								} else if ("b".equals(rend) || "bold".equals(rend)) {
 									pagedWriter.writeStartElement("b", ["class":rend])
+								} else {
+									if ("emph".equals(localname)) {
+										pagedWriter.writeStartElement("i", ["class":rend])
+									} else { // hi
+										pagedWriter.writeStartElement("b", ["class":rend])
+									}
 								}
-							}
-							break;
-						case "p":
-						//case "lg":
-							pagedWriter.write("\n");
-							pagedWriter.writeStartElement("p", ["class":rend])
-							break;
-						case "div":
-						case "div1":
-						case "div2":
-						case "div3":
-						case "div4":
-						case "div5":
-							pagedWriter.writeStartElement("div", ["class":rend, "type":localname])
-							break;
-						case "lb":
-						//case "l":
-							pagedWriter.writeEmptyElement("br", ["class":rend])
-							break;
-						case wordTag:
-							wordid = getAttributeValue(parser, null,"id");
-							
-							wordcount++;
-							if (wordcount >= wordmax) {
-								createNextOutput();
-							}
-							
-							if (firstWord) {
-								firstWord = false;
-								this.idxstart.add(wordid);
-							}
-							
-							break;
-						case "ana":
-							flaginterp=true;
-							interpvalue+=" "+getAttributeValue(parser, null, "type").substring(1)+":"
-							break;
-						case "form":
-							wordvalue="";
-							interpvalue ="";
-							flagform=true;
-							break;
-						default:
-							if (noteElements.contains(localname)) {
-								flagNote = true;
-								noteContent = ""
-							}
-//							 else {
-//								pagedWriter.writeStartElement("span", ["class":localname])
-//							}
-							break;
-					}
-					break;
-				case XMLStreamConstants.END_ELEMENT:
-					localname = parser.getLocalName();
-					if (currentOutOfTextElements.size() > 0) currentOutOfTextElements.pop()
-					writeOutOfTextToEditText = currentOutOfTextElements.size() > 0
-					
-					switch (localname) {
-						case "p":
-						//case "lg":
-							pagedWriter.writeEndElement() // </p>
-							pagedWriter.write("\n");
-							break;
-						case "div":
-						case "div1":
-						case "div2":
-						case "div3":
-						case "div4":
-						case "div5":
-							pagedWriter.writeEndElement() // </div>
-							pagedWriter.write("\n");
-						case "head":
-							pagedWriter.writeEndElement() // </h2>
-							pagedWriter.write("\n");
-							break;
-						case "list":
-							pagedWriter.writeEndElement(); // ul or ol
-							pagedWriter.write("\n");
-							break
-						case "item":
-							pagedWriter.writeEndElement(); // li
-							pagedWriter.write("\n");
-							break;
-						case "hi":
-							pagedWriter.writeEndElement(); // b
-							break;
-						case "emph":
-							pagedWriter.writeEndElement(); // i
-							break;
-						case "table":
-							pagedWriter.writeEndElement(); // table
-							pagedWriter.write("\n");
-							break;
-						case "row":
-							pagedWriter.writeEndElement(); // tr
-							break;
-						case "cell":
-							pagedWriter.writeEndElement(); // td
-							break;
-						case "ref":
-							pagedWriter.writeEndElement() // </a>
-							break;
-						case "form":
-							flagform = false
-							break;
-						case "ana":
-							flaginterp = false
-							break;
-						case wordTag:
-							int l = lastword.length();
-							String endOfLastWord = "";
-							if (l > 0)
-								endOfLastWord = lastword.subSequence(l-1, l);
+								break;
+							case "p":
+							//case "lg":
+								pagedWriter.write("\n");
+								pagedWriter.writeStartElement("p", ["class":rend])
+								break;
+							case "div":
+							case "div1":
+							case "div2":
+							case "div3":
+							case "div4":
+							case "div5":
+								pagedWriter.writeStartElement("div", ["class":rend, "type":localname])
+								break;
+							case "lb":
+							//case "l":
+								pagedWriter.writeEmptyElement("br", ["class":rend])
+								break;
+							case wordTag:
+								wordid = getAttributeValue(parser, null,"id");
 
-							if (interpvalue != null)
-								interpvalue = interpvalue;
+								wordcount++;
+								if (wordcount >= wordmax) {
+									createNextOutput();
+								}
 
-							if (NoSpaceBefore.contains(wordvalue) ||
-							NoSpaceAfter.contains(lastword) ||
-							wordvalue.startsWith("-") ||
-							NoSpaceAfter.contains(endOfLastWord)) {
-								pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid]);
-							} else {
-								pagedWriter.writeCharacters(" ");
-								pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid]);
-							}
+								if (firstWord) {
+									firstWord = false;
+									this.idxstart.add(wordid);
+								}
 
-							pagedWriter.writeCharacters(wordvalue);
-							pagedWriter.writeEndElement();
-							pagedWriter.writeComment("\n")
-							lastword=wordvalue;
-							break;
-						default:
-							if (noteElements.contains(localname)) {
-								flagNote = false;
-								if (noteContent.length() > 0) {
-									notes << noteContent;
-									pagedWriter.writeStartElement("a", ["href":"#note_"+notes.size(), "name":"noteref_"+notes.size(), "title":noteContent]);
-									pagedWriter.writeStartElement("sup")
-									pagedWriter.writeCharacters(""+notes.size())
-									pagedWriter.writeEndElement() // </sub>
-									pagedWriter.writeEndElement() // </span>
+								break;
+							case "ana":
+								flaginterp=true;
+								interpvalue+=" "+getAttributeValue(parser, null, "type").substring(1)+":"
+								break;
+							case "form":
+								wordvalue="";
+								interpvalue ="";
+								flagform=true;
+								break;
+							default:
+								if (noteElements.contains(localname)) {
+									flagNote = true;
+									noteContent = ""
 								}
-							} 
-//							else {
-//								pagedWriter.writeEndElement() // the element
-//							}
-							break;
-					}
-					break;
-				case XMLStreamConstants.CHARACTERS:
-					if (flagform && parser.getText().length() > 0) {
-						wordvalue+=(parser.getText());
-						if (flagNote == parser.getText().length() > 0)
+							//							 else {
+							//								pagedWriter.writeStartElement("span", ["class":localname])
+							//							}
+								break;
+						}
+						break;
+					case XMLStreamConstants.END_ELEMENT:
+						localname = parser.getLocalName();
+						if (currentOutOfTextElements.size() > 0) currentOutOfTextElements.pop()
+						writeOutOfTextToEditText = currentOutOfTextElements.size() > 0
+
+						switch (localname) {
+							case "text":
+								break;
+							case "p":
+							//case "lg":
+								pagedWriter.writeEndElement() // </p>
+								pagedWriter.write("\n");
+								break;
+							case "div":
+							case "div1":
+							case "div2":
+							case "div3":
+							case "div4":
+							case "div5":
+								pagedWriter.writeEndElement() // </div>
+								pagedWriter.write("\n");
+								break;
+							case "head":
+								pagedWriter.writeEndElement() // </h2>
+								pagedWriter.write("\n");
+								break;
+							case "list":
+								pagedWriter.writeEndElement(); // ul or ol
+								pagedWriter.write("\n");
+								break
+							case "item":
+								pagedWriter.writeEndElement(); // li
+								pagedWriter.write("\n");
+								break;
+							case "hi":
+								pagedWriter.writeEndElement(); // b
+								break;
+							case "emph":
+								pagedWriter.writeEndElement(); // i
+								break;
+							case "table":
+								pagedWriter.writeEndElement(); // table
+								pagedWriter.write("\n");
+								break;
+							case "row":
+								pagedWriter.writeEndElement(); // tr
+								break;
+							case "cell":
+								pagedWriter.writeEndElement(); // td
+								break;
+							case "ref":
+								pagedWriter.writeEndElement() // </a>
+								break;
+							case "form":
+								flagform = false
+								break;
+							case "ana":
+								flaginterp = false
+								break;
+							case wordTag:
+								int l = lastword.length();
+								String endOfLastWord = "";
+								if (l > 0)
+									endOfLastWord = lastword.subSequence(l-1, l);
+
+								if (interpvalue != null)
+									interpvalue = interpvalue;
+
+								if (NoSpaceBefore.contains(wordvalue) ||
+								NoSpaceAfter.contains(lastword) ||
+								wordvalue.startsWith("-") ||
+								NoSpaceAfter.contains(endOfLastWord)) {
+									pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid]);
+								} else {
+									pagedWriter.writeCharacters("\n");
+									pagedWriter.writeStartElement("span", ["title":interpvalue, "id":wordid]);
+								}
+
+								pagedWriter.writeCharacters(wordvalue);
+								pagedWriter.writeEndElement();
+								//pagedWriter.writeComment("\n")
+								lastword=wordvalue;
+								break;
+							default:
+								if (noteElements.contains(localname)) {
+									flagNote = false;
+									if (noteContent.length() > 0) {
+										notes << noteContent;
+										pagedWriter.writeStartElement("a", ["href":"#note_"+notes.size(), "name":"noteref_"+notes.size(), "title":noteContent]);
+										pagedWriter.writeStartElement("sup")
+										pagedWriter.writeCharacters(""+notes.size())
+										pagedWriter.writeEndElement() // </sub>
+										pagedWriter.writeEndElement() // </a>
+									}
+								}
+							//							else {
+							//								pagedWriter.writeEndElement() // the element
+							//							}
+								break;
+						}
+						break;
+					case XMLStreamConstants.CHARACTERS:
+						if (flagform && parser.getText().length() > 0) {
+							wordvalue+=(parser.getText());
+							if (flagNote == parser.getText().length() > 0)
+								noteContent += parser.getText().replace("\n", " ");
+						} else	if (flaginterp && parser.getText().length() > 0) {
+							interpvalue+=(parser.getText());
+						} else if (flagNote == parser.getText().length() > 0) {
 							noteContent += parser.getText().replace("\n", " ");
-					} else	if (flaginterp && parser.getText().length() > 0) {
-						interpvalue+=(parser.getText());
-					} else if (flagNote == parser.getText().length() > 0) {
-						noteContent += parser.getText().replace("\n", " ");
-					} else if (writeOutOfTextToEditText) {
-						pagedWriter.writeCharacters(parser.getText())
-					}
-					break;
+						} else if (writeOutOfTextToEditText) {
+							pagedWriter.writeCharacters(parser.getText())
+						}
+						break;
+				}
 			}
+			closeMultiWriter();
+		} catch(Exception e) {
+			println "** Fail to build $infile edition: $e at "+parser.getLocation()
+			println "** resulting file: $outfile"
+			println "** Stax stack: "+pagedWriter.getTagStack()
+			e.printStackTrace();
+			pagedWriter.close()
+			return false;
 		}
-		closeMultiWriter();
+		return true;
 	}
 }
Index: tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/AnnotationInjectionFilter.groovy
===================================================================
--- tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/AnnotationInjectionFilter.groovy	(revision 1618)
+++ tmp/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/AnnotationInjectionFilter.groovy	(revision 1619)
@@ -120,7 +120,7 @@
 			switch (localname) {
 				case "w":
 					start = false
-					if (data.keySet().size() > 0) writer.writeCharacters("\n");
+					if (data.keySet().size() > 0) writer.writeComment("\n");
 					// write remaining properties
 					if (debug) if (data.size() > 0) println "new ana: " +data
 					for (def prop : data.keySet()) { // (1)
@@ -130,7 +130,7 @@
 						writer.writeAttribute("type", "#$prop")
 						writer.writeCharacters(data.get(prop))
 						writer.writeEndElement()
-						writer.writeCharacters("\n")
+						writer.writeComment("\n")
 						println " create annotation $prop with "+data.get(prop)
 					}
 					break;
Index: tmp/org.txm.groovy.core/src/groovy/org/txm/macro/nlp/TT2XMLInDirectoryMacro.groovy
===================================================================
--- tmp/org.txm.groovy.core/src/groovy/org/txm/macro/nlp/TT2XMLInDirectoryMacro.groovy	(revision 1618)
+++ tmp/org.txm.groovy.core/src/groovy/org/txm/macro/nlp/TT2XMLInDirectoryMacro.groovy	(revision 1619)
@@ -64,7 +64,7 @@
 				writer.writeAttribute("frlemma", sent_m[0][3])
 				writer.writeCharacters(sent_m[0][3])
 				writer.writeEndElement() // close w		
-				writer.writeCharacters("\n")
+				writer.writeComment("\n")
 				writer.writeEndElement() // close s
 				writer.writeEndElement() // close p (sent)
 				writer.writeCharacters("\n")
Index: tmp/org.txm.groovy.core/src/groovy/org/txm/macro/xml/XMLStatistics.groovy
===================================================================
--- tmp/org.txm.groovy.core/src/groovy/org/txm/macro/xml/XMLStatistics.groovy	(revision 1618)
+++ tmp/org.txm.groovy.core/src/groovy/org/txm/macro/xml/XMLStatistics.groovy	(revision 1619)
@@ -1,4 +1,4 @@
-package org.txm.scripts.scripts
+package org.txm.macro.xml
 
 import java.text.Collator;
 import java.util.Locale;
Index: tmp/org.txm.core/src/java/org/txm/scripts/importer/StaxStackWriter.groovy
===================================================================
--- tmp/org.txm.core/src/java/org/txm/scripts/importer/StaxStackWriter.groovy	(revision 1618)
+++ tmp/org.txm.core/src/java/org/txm/scripts/importer/StaxStackWriter.groovy	(revision 1619)
@@ -12,6 +12,7 @@
 	XMLStreamWriter writer;
 	OutputStream output;
 	def events = [];
+	def debug = false
 	
 	public StaxStackWriter(File file) {
 		this(new BufferedOutputStream(new FileOutputStream(file)));
@@ -185,7 +186,8 @@
 	@Override
 	public void writeEndElement () throws XMLStreamException {
 		writer.writeEndElement();
-		events.pop()
+		events.remove(events.size()-1)
+		if (debug) println "END: $events"
 
 	}
 
@@ -233,6 +235,7 @@
 	public void writeStartElement (String localName) throws XMLStreamException {
 		writer.writeStartElement(localName);
 		events << localName
+		if (debug) println "START $localName $events"
 
 	}
 	
@@ -248,6 +251,7 @@
 	throws XMLStreamException {
 		writer.writeStartElement(namespaceURI, localName);
 		events << localName
+		if (debug) println "START $localName $events"
 	}
 
 	@Override
@@ -255,5 +259,6 @@
 	String namespaceURI) throws XMLStreamException {
 		writer.writeStartElement(prefix, localName, namespaceURI);
 		events << localName
+		if (debug) println "START $localName $prefix $events"
 	}
 }
Index: tmp/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/messages/messages_fr.properties
===================================================================
--- tmp/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/messages/messages_fr.properties	(revision 1618)
+++ tmp/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/messages/messages_fr.properties	(revision 1619)
@@ -1,4 +1,5 @@
 savingP0Annotations=Enregistrement de {0} annotations...
 annotationSuccessfullyWritten=Annotations enregistrées.
 savingAnnotations=Enregistrement des annotations
-annotationSuccesfullyWritten=Annotations enregistrées dans le fichier {0}.
\ No newline at end of file
+annotationSuccesfullyWritten=Annotations enregistrées.
+annotationSuccesfullyWrittenIntheP0File=Annotations enregistrées dans le fichier {0}.
\ No newline at end of file
Index: tmp/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/messages/messages.properties
===================================================================
--- tmp/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/messages/messages.properties	(revision 1618)
+++ tmp/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/messages/messages.properties	(revision 1619)
@@ -1,4 +1,4 @@
 savingP0Annotations=Saving {0} annotations...
 annotationSuccessfullyWritten=Annotations successfully written.
-savingAnnotations=Saving annotations
-annotationSuccesfullyWritten=Annotations successfully written in the {0} file.
\ No newline at end of file
+annotationSuccesfullyWrittenIntheP0File=Annotations successfully written in the {0} file.
+savingAnnotations=Saving annotations.
\ No newline at end of file
Index: tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/UpdateCorpus.java
===================================================================
--- tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/UpdateCorpus.java	(revision 1618)
+++ tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/workspace/UpdateCorpus.java	(revision 1619)
@@ -21,10 +21,10 @@
 public class UpdateCorpus extends AbstractHandler {
 
 	public static final String ID = UpdateCorpus.class.getCanonicalName();
-	
+
 	@Override
 	public Object execute(ExecutionEvent event) throws ExecutionException {
-		
+
 		ISelection sel = (IStructuredSelection) HandlerUtil.getCurrentSelection(event);
 		if (!(sel instanceof IStructuredSelection)) return null;
 		IStructuredSelection selection = (IStructuredSelection) sel;
@@ -34,39 +34,46 @@
 			return null;
 		MainCorpus corpus = (MainCorpus) s;
 		update(corpus);
-		
+
 		return corpus;
 	}
-	
+
 	public static JobHandler update(final MainCorpus corpus) {
-		
+
 		final Project project = corpus.getProject();
 		if (project == null)  return null;
-		
-		if (!project.getImportModuleName().matches("xtz|txt|hyperbase|cnr|alceste|xml")) {
+
+		String iname = project.getImportModuleName();
+		if (!iname.matches("xtz|txt|hyperbase|cnr|alceste|xml|xmltxm")) {
 			System.out.println("Can't update a corpus not imported with the XTZ import module.");
 			return null;
 		}
-		
-		Display.getDefault().syncExec(new Runnable() {
-			@Override
-			public void run() {CloseEditorsUsing.corpus(corpus);}
-		});
-		
+
+		Display d = Display.getCurrent();
+		if (d == null) {
+			d = Display.getDefault();
+		}
+		if (d != null) {
+			d.syncExec(new Runnable() {
+				@Override
+				public void run() {CloseEditorsUsing.corpus(corpus);}
+			});
+		}
+
 		project.setDirty();
 		project.setNeedToBuild();
 		project.setDoMultiThread(false); //too soon
 		project.setDoUpdate(true);
 		project.setImportModuleName("xtz");
-		
+
 		JobHandler job = new JobHandler("Updating corpus "+corpus+" using "+project) {
-			
+
 			@Override
 			protected IStatus run(IProgressMonitor monitor) {
 				if (project.compute(monitor)) {
-					
+
 					this.syncExec(new Runnable() {
-						
+
 						@Override
 						public void run() {
 							RestartTXM.reloadViews();
@@ -78,15 +85,15 @@
 				}
 			}
 		};
-		
+
 		job.schedule();
-		
-////		String txmhome = Toolbox.getTxmHomePath();
-////		File scriptDir = new File(txmhome, "scripts/groovy/user/org/txm/scripts/importer/xtz");
-////		File script = new File(scriptDir, "xtzLoader.groovy");
-//		System.out.println();
-//		JobHandler ret = ExecuteImportScript.executeScript(project);
-//		
+
+		////		String txmhome = Toolbox.getTxmHomePath();
+		////		File scriptDir = new File(txmhome, "scripts/groovy/user/org/txm/scripts/importer/xtz");
+		////		File script = new File(scriptDir, "xtzLoader.groovy");
+		//		System.out.println();
+		//		JobHandler ret = ExecuteImportScript.executeScript(project);
+		//		
 		return job;
 	}
 }
\ No newline at end of file
Index: tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java
===================================================================
--- tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java	(revision 1618)
+++ tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java	(revision 1619)
@@ -457,7 +457,7 @@
 			//			}
 
 
-			if (this.getResult().isLocked()) {
+			if (this.getResult() != null && this.getResult().isLocked()) {
 				this.setLocked(true);
 			}
 
Index: tmp/org.txm.rcp/plugin.xml
===================================================================
--- tmp/org.txm.rcp/plugin.xml	(revision 1618)
+++ tmp/org.txm.rcp/plugin.xml	(revision 1619)
@@ -1007,6 +1007,20 @@
                   visible="true">
             </separator>
             <command
+                  commandId="org.txm.rcp.commands.workspace.UpdateCorpus"
+                  icon="icons/functions/update.png"
+                  label="Re-import corpus"
+                  style="push">
+               <visibleWhen
+                     checkEnabled="false">
+                  <or>
+                     <reference
+                           definitionId="OneMainCorpusSelected">
+                     </reference>
+                  </or>
+               </visibleWhen>
+            </command>
+            <command
                   commandId="org.txm.rcp.handlers.results.DeleteObject"
                   icon="icons/functions/Delete.png"
                   style="push">
