Skip to content

FreeDict HOWTO – Editing TEI XML

Sebastian Humenda edited this page Jul 8, 2020 · 3 revisions

Editing TEI XML

To edit XML, it is necessary to have a good editor. Microsoft Word or LibreOffice are generally unsuited for this task. It is up to you whether you pick a good general-purpose editor or a specialised XML editor. This section details some configuration hints for editors FreeDict members use and we kindly ask for more input here or on the mailing list.

The editor you choose should have at least syntax highlighting and some XML support. You can try the most nerdy ones like VIM or EMACS, you can use Eclipse (only if you're familiar with it) or switch to something like Gedit.

Vim

Vi improved is a text editor for the command line and the graphical user interface. It has a steep learning curve, but it pays off with very efficient editing speed. This section will give a short and not by and means exhaustive list of Vim plugins, which help to edit TEI xml.

  • Snipmate:

    Snipmate is able to provide completion and auto-fill-in-capabilities on a per-keyword basis. It is able to execute functions to fill in certain parts in the code and offers many more features not listed here.

    If SnipMate has been set up locally in ~/.vim, a folder called "snippets" exists. In there are all the snippets which SnipMate understands. If you want to edit a file, rename it by appending "-my" to the file name, so that the files won't be overridden, when an update is installed.

    The tei-my.snippets can look like this (see explanations below):

    snippet <
    	<${1:tag}>${2}</$1>
    snippet <<
    	<${1:tag}>
    		${2}
    	</$1>
    snippet orth
    	<orth>${1}</orth>${2}
    snippet entry
    	<entry>
    		${1}
    	</entry>
    snippet form
    	<form>
    		${1}
    	</form>
    snippet sense
    	<sense>
    		${1}
    	</sense>
    snippet gram
    	<gramGrp>
    		${1}
    	</gramGrp>
    snippet pos
    	<pos>${1:v}</pos>${2}
    snippet note
    	<note type="usage">${1}</note>
    snippet cit
    	<cit type="trans">
    		<quote>${1}</quote>
    	</cit>
    snippet gen
    	<gen>${1}</gen>${2}
    snippet <
    	<${1:tag}>${2}</$1>
    snippet <<
    	<${1:tag}>
    		${2}
    	</$1>
    

    The first thing to note is that the indentation within the file HAS TO BE a tab character. In the first declaration, a snippet called "<" is created. If "<" is typed in a TEI file and followed by a tab key press, <tag></tag> is inserted and the curser is at tag. If the user now starts typing, e.g. "foo", tag will be replaced with the typed character. So after typing foo, the text is <foo></foo> (the second foo is inserted automatically). Another tab will bring the user to the contents of the tag.
    The $ signs within the snippet body can be used to address the regions to tab to, i.e. the arguments.

  • XML.vim This plugin eases the editing of Vim scripts.

Xemacs

Xemacs supports all the above features. Of particular note are the functionalities Xemacs (and to a slightly lesser extent GNU Emacs) provides in editing XML and SGML based documents. Xemacs, once it has associated a document with a DTD, gives right mouse button options that are compliant with the DTD and the ability to validate XML files.

Xemacs configuration quick start

Abstract

Here I assume you have installed Xemacs with or without full support for MULE (Multi User Language Environment). You may not need all of that functionality and it should do everything we need without it. It doesn't hurt and may be useful for your other work.

Before configuring, make sure you have the psgml and Mule-UCS packets installed. You can check this by ...TODO

If you have a fresh install, all you need to do is configure the interface so that you can bear it. It is surprisingly ugly out of the box (though functional :)

Configuring and extending emacsen is a lifetime's work. :) Lets just do some basic stuff.

At the single user level (your own configuration when running under your own account), there are two main files (by default) that you may like to tweak. Your .Xdefaults file and the .xemacs/custom.el file.

Following are copies of mine just copy them over the file of the same name (which of course you will backup first... you may hate my configs even more!).

A home dot Xdefaults file

You will find the original of the .Xdefaults file under the help menu in the Xemacs interface (top right hand corner). This file is essentially the default that comes with Xemacs with a few things tweaked. Please note that the most of the working font settings are actually done in the next file. As a bonus you also get some configs (colours only) for Xcalendar :)

~/.Xdefaults

This is a very comprehensive .Xdefaults file. Note however, that most settings are either at defaults or commented (!) out.

!
! You can use the examples below as a basis for your own customisations:
! copy and modify any of the resources below into your own ~/.Xdefaults file.
! .Xdefaults specifies defaults for all applications, not just Xemacs; it is
! normally used to customise fonts, colours, and the like, while ~/.emacs is
! used to change other sorts of (Xemacs-specific) behaviour.

! READ THIS NOW
! =============
! In general, changes to your .Xdefaults file will not take effect until the
! next time you restart the window system.  To reload your resources
! explicitly, use the shell command
!
!   xrdb -load ~/.Xdefaults
!
! The resources will take effect the next time you restart Xemacs.  (Simply
! creating a new xemacs frame is not enough - you must restart the editor
! for the changes to take effect.)
!



! Colours and backgrounds.
! ======================
! The contrasts of these colours will cause them to map to the appropriate
! one of "black" or "white" on monochrome systems.
!
! The valid colour names on your system can be found by looking in the file
! `rgb.txt', usually found in /usr/lib/X11/ or /usr/openwin/lib/X11/.

! You may have xcolorsel or xcolors installed which show you the real rendered colours
! Set the foreground and background colours of the `default' face.
! The default face colours are the base for most of the other faces'
! colours.  The default background is gray80, and the default foreground
! is black.
Emacs.default.attributeBackground:  seashell
Emacs.default.attributeForeground:  black

! Set the modeline colors.
Emacs.modeline*attributeForeground: darkblue
Emacs.modeline*attributeBackground: LightSteelBlue3

! Set the colour of the text cursor.
Emacs.text-cursor*attributeBackground: SpringGreen4

! If you want to set the colour of the mouse pointer, do this:
 Emacs.pointer*attributeForeground: red1
! If you want to set the background of the mouse pointer, do this:
 Emacs.pointer*attributeBackground: skyblue
! Note that by default, the pointer foreground and background are the same
! as the default face.

! Set the menubar colours.  This overrides the default foreground and
! background colours specified above.
Emacs*menubar*Foreground:       grey50
Emacs*menubar*Background:    DarkSlateGray3
! This is for buttons in the menubar.
! Yellow would be better, but that would map to white on monochrome.
Emacs*menubar.buttonForeground: Blue
Emacs*XlwMenu.selectColor:      Green
Emacs*XmToggleButton.selectColor: CornflowerBlue

! Specify the colours of popup menus.
Emacs*popup*Foreground:  VioletRed4
Emacs*popup*Background: PaleTurquoise3

! Specify the colours of the various sub-widgets of the dialog boxes.
Emacs*dialog*Foreground:        Black
! #A5C0C1 is a shade of blue
Emacs*dialog*Background:        CadetBlue2
! The following three are for Motif dialog boxes ...
Emacs*dialog*XmTextField*Background:    WhiteSmoke
Emacs*dialog*XmText*Background: WhiteSmoke
Emacs*dialog*XmList*Background: WhiteSmoke
! While this one is for Athena dialog boxes.
Emacs*dialog*Command*Background:    WhiteSmoke

! Athena dialog boxes are sometimes built with the Xaw3d
! variant of the Athena toolkit.
! XEmacs being nice to 8bit displays, it defaults to:
Emacs*dialog*Command*beNiceToColormap:  true
! If you are shocked by the ugliness of the 3d rendition,
! you may want to set (even on 8bit displays) the above to false.

! Xlw Scrollbar colours
Emacs*XlwScrollBar.Foreground:  Gray30
Emacs*XlwScrollBar.Background:  Gray75
Emacs*XmScrollBar.Foreground:       Gray30
Emacs*XmScrollBar.Background:       DarkSeaGreen4

!
! The Lucid Scrollbar supports two added resources, SliderStyle is either
! "plain" (default) or "dimple".  Dimple puts a small dimple in the middle
! of the slider that depresses when the slider is clicked on.  ArrowPosition is
! either "opposite" (default) or "same".  Opposite puts the arrows at opposite
! of the scrollbar, same puts both arrows at the same end, like the Amiga.
!
 Emacs*XlwScrollBar.SliderStyle:    dimple
 Emacs*XlwScrollBar.ArrowPosition:  opposite


!
! If you want to turn off a tool bar, set its height or width to 0.
! The correct size value is not really arbitrary.  We only control it
! this way in order to avoid excess frame resizing when turning the
! tool bars on and off.
!
! To change the heights and widths of the tool bars:
!
! Emacs.topToolBarHeight:   37
! Emacs.bottomToolBarHeight:    10
! Emacs.leftToolBarWidth:   10
! Emacs.rightToolBarWidth:  10
! these set Highlight Colours Around The Top Icon Based Menu
Emacs*topToolBarShadowColor:    Lavender
Emacs*bottomToolBarShadowColor: skyblue
! This is the Top Icon Menu Background Colour
Emacs*backgroundToolBarColor:    SteelBlue4
Emacs*toolBarShadowThickness:       2


! If you want to turn off vertical scrollbars, or change the default
! pixel width of the vertical scrollbars, do it like this (0 width
! means no vertical scrollbars):
!
! Emacs.scrollBarWidth: 0
!
! To change it for a particular frame, do this:
!
! Emacs*FRAME-NAME.scrollBarWidth: 0


! If you want to turn off horizontal scrollbars, or change the default
! pixel height of the horizontal scrollbars, do it like this (0 height
! means no horizontal scrollbars):
!
! Emacs.scrollBarHeight: 0
!
! To change it for a particular frame, do this:
!
! Emacs*FRAME-NAME.scrollBarHeight: 0


! To dynamically change the labels used for menubar buttons...
!
Emacs*XlwMenu.resourceLabels: True
Emacs*XlwMenu.newFrame.labelString: Open Another Window

! To have the Motif scrollbars on the left instead of the right, do this:
!
! Emacs*scrollBarPlacement: BOTTOM_LEFT
!
! To have the Athena scrollbars on the right, use `BOTTOM_RIGHT' instead

! To have Motif scrollbars act more like Xt scrollbars...
!
! Emacs*XmScrollBar.translations: #override \n\
!     <Btn1Down>:     PageDownOrRight(0)    \n\
!     <Btn3Down>:     PageUpOrLeft(0)

! Fonts.
! ======
! NOTE: This now sets only the menu bar and mini buffer fonts (which are  direct Xresources ).
! XEmacs requires the use of XLFD (X Logical Font Description) format font
! names, which look like
!
!   *-courier-medium-r-*-*-*-120-*-*-*-*-*-*
!
! if you use any of the other, less strict font name formats, some of which
! look like
!       lucidasanstypewriter-12
! and       fixed
! and       9x13
!
! then XEmacs won't be able to guess the names of the bold and italic versions.
! All X fonts can be referred to via XLFD-style names, so you should use those
! forms.  See the man pages for X(1), xlsfonts(1), and xfontsel(1).
! The font attributes are now set in your .xemacs/custom.el file

! The default font for the text area of XEmacs is chosen at run-time
! by lisp code which tries a number of different possibilities in order
! of preference.  If you wish to override it, use this:
!
! Emacs.default.attributeFont:  -*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-*

! If you choose a font which does not have an italic version, you can specify
! some other font to use for it here:
!
! Emacs.italic.attributeFont:  -*-courier-medium-o-*-*-*-120-*-*-*-*-iso8859-*
!
! And here is how you would set the background colour of the `highlight' face,
! but only on the screen named `debugger':
!
! Emacs*debugger.highlight.attributeBackground:     PaleTurquoise
!
! See the NEWS file (C-h n) for a more complete description of the resource
! syntax of faces.


! Font of the modeline, menubar and pop-up menus.
! Note That the Menubar Resources Do Not Use the `Face' Syntax, Since They
! Are X Toolkit Widgets and Thus Outside the Domain of Xemacs Proper.
!
Emacs.default.attributeFont:  -*-*-medium-r-*-*-*-120-*-*-m-*-*-*
Emacs*menubar*font:           fixed
Emacs.modeline.attributeFont: fixed
!Emacs*menubar*Font:        -*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-*
!Emacs*popup*Font:      -*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-*
!Emacs*menubar*Font: -adobe-avant garde gothic-*-r-normal-*-12-120-75-75-p-*-iso8859-15

!Emacs*popup*Font: -adobe-avant garde gothic-*-r-normal-*-12-120-75-75-p-*-iso8859-15
! Font in the Motif dialog boxes.
! (Motif uses `fontList' while most other things use `font' - if you don't
! know why you probably don't want to.)
!
!MOTIF list all commented out (pete) feb 2004
!Emacs*XmDialogShell*FontList:  -*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-*
!Emacs*XmTextField*FontList:    -*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-*
!Emacs*XmText*FontList:     -*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-*
!Emacs*XmList*FontList:     -*-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-*

! Font in the Athena dialog boxes.
! I think 14-point looks nicer than 12-point.
! Some people use 12-point anyway because you get more text, but
! there's no purpose at all in doing this for dialog boxes.

!Emacs*Dialog*Font:  -adobe-avant garde gothic-*-r-normal-*-12-120-75-75-p-*-iso8859-15

! Dialog box translations.
! =======================

! This accelerator binds <return> in a dialog box to <activate> on button1
Emacs*dialog*button1.accelerators:#override\
<KeyPress>Return: ArmAndActivate()\n\
<KeyPress>KP_Enter: ArmAndActivate()\n\
Ctrl<KeyPress>m: ArmAndActivate()\n

! Translations to make the TextField widget behave more like XEmacs
Emacs*XmTextField.translations: #override\n\
    !<Key>osfBackSpace: delete-previous-character()\n\
    !<Key>osfDelete:    delete-previous-character()\n\
    !Ctrl<Key>h:        delete-previous-character()\n\
    !Ctrl<Key>d:        delete-next-character()\n\
    !Meta<Key>osfDelete:    delete-previous-word()\n\
    !Meta<Key>osfBackSpace: delete-previous-word()\n\
    !Meta<Key>d:        delete-next-word()\n\
    !Ctrl<Key>k:        delete-to-end-of-line()\n\
    !Ctrl<Key>g:        process-cancel()\n\
    !Ctrl<Key>b:        backward-character()\n\
    !<Key>osfLeft:      backward-character()\n\
    !Ctrl<Key>f:        forward-character()\n\
    !<Key>osfRight:     forward-character()\n\
    !Meta<Key>b:        backward-word()\n\
    !Meta<Key>osfLeft:  backward-word()\n\
    !Meta<Key>f:        forward-word()\n\
    !Meta<Key>osfRight: forward-word()\n\
    !Ctrl<Key>e:        end-of-line()\n\
    !Ctrl<Key>a:        beginning-of-line()\n\
    !Ctrl<Key>w:        cut-clipboard()\n\
    !Meta<Key>w:        copy-clipboard()\n\
    <Btn2Up>:       copy-primary()\n

! With the XEmacs typeahead it's better to not have space be bound to
! ArmAndActivate() for buttons that appear in dialog boxes.  This is
! not 100% Motif compliant but the benefits far outweigh the
! compliance problem.
Emacs*dialog*XmPushButton.translations:#override\n\
    <Btn1Down>:         Arm()\n\
    <Btn1Down>,<Btn1Up>: Activate()\
            Disarm()\n\
    <Btn1Down>(2+):     MultiArm()\n\
    <Btn1Up>(2+):       MultiActivate()\n\
    <Btn1Up>:           Activate()\
                Disarm()\n\
    <Key>osfSelect:     ArmAndActivate()\n\
    <Key>osfActivate:   ArmAndActivate()\n\
    <Key>osfHelp:   Help()\n\
    ~Shift ~Meta ~Alt <Key>Return:  ArmAndActivate()\n\
    <EnterWindow>:      Enter()\n\
    <LeaveWindow>:      Leave()\n

! XIM input method style
! =======================

! ximStyles is a (whitespace or comma-separated) list of XIMStyles in
! order of user's preference.
! Choose a subset of the following styles or reorder to taste
Emacs*ximStyles: XIMPreeditPosition|XIMStatusArea\
            XIMPreeditPosition|XIMStatusNothing\
            XIMPreeditPosition|XIMStatusNone\
            XIMPreeditNothing|XIMStatusArea\
            XIMPreeditNothing|XIMStatusNothing\
            XIMPreeditNothing|XIMStatusNone\
            XIMPreeditNone|XIMStatusArea\
            XIMPreeditNone|XIMStatusNothing\
            XIMPreeditNone|XIMStatusNone

! XIM Preedit and Status foreground and background
Emacs*EmacsFrame.ximForeground: black
Emacs*EmacsFrame.ximBackground: white

! XIM fontset (defaults to system fontset default)
! Emacs*EmacsFrame.FontSet: -dt-interface user-medium-r-normal-s*-*-*-*-*-*-*-*-*


!Xcalendar .Xdefault settings
! colours
! Note: These may cause problems using the -rv option on monochrome displays

xcalendar.*Background: SkyBlue1
xcalendar.*markBackground: LightCyan3
xcalendar.*helpButton*Background: SteelBlue3
xcalendar.*daynames*Background: SteelBlue3
xcalendar.*quitButton*Foreground: White
xcalendar.*editorTitle*Background: DarkSlateGray1

A home dot xemacs/custom.el file

Most of the following should be OK for a normal xemacs install. All of them may be set from the options menus. Start with the first set of menus that Options open and set your email addresses and any other first level preferences. You save them by choosing the save options to init file right at the bottom of the opening dialog (which rather confusingly saves the file ~/.xemacs/custom.el). You are best to leave the ~/.xemacs/init.el file alone for now. One other word of advice is to not edit this file too much by hand, as the syntax is very strict and unforgiving. If it doesn't work, remove it and start again.

~/.xemacs/custom.el

(custom-set-variables
 '(require-final-newline t)
 '(init-face-from-resources nil)
 '(strokes-mode t nil (strokes))
 '(shell-input-autoexpand (quote history))
 '(european-calendar-style t)
 '(font-menu-ignore-scaled-fonts t)
 '(mwheel-follow-mouse t)
 '(paren-message-no-match t)
 '(x-face-xmas-like-highlight-headers t)
 '(mail-from-style (quote angles))
 '(bbdb/mail-auto-create-p (quote prompt))
 '(mail-header-separator "--message text follows this line--")
 '(mail-signature "")
 '(sc-citation-delimiter "/>")
 '(paren-no-match-face (quote paren-face-no-match))
 '(mouse-avoidance-nudge-dist 10)
 '(mouse-avoidance-mode (quote animate) nil (avoid))
 '(paren-message-linefeed-display " RET ")
 '(mail-abbrev-mailrc-file "~/.mailrc")
 '(sc-default-author-name "Somebody")
 '(sc-default-attribution "Unknown")
 '(paren-message-show-linenumber (quote absolute))
 '(scroll-conservatively 2)
 '(next-screen-context-lines 4)
 '(mail-alias-separator-string ",\\n ")
 '(bbdb-north-american-phone-numbers-p nil)
 '(toolbar-captioned-p nil)
 '(eudc-max-servers-to-query 2)
 '(progress-feedback-use-echo-area t)
 '(ibuffer-use-other-window t)
 '(mouse-track-scroll-delay 100)
 '(browse-url-browser-function (quote browse-url-mozilla))
 '(dictionary-server "localhost")
 '(buffers-menu-format-buffer-line-function (quote slow-format-buffers-menu-line))
 '(ibuffer-default-shrink-to-minimum-size t)
 '(bbdb/vm-update-records-mode (quote (if (vm-new-flag msg) (quote annotating) (quote searching))))
 '(pending-delete-mode t nil (pending-del))
 '(face-frob-from-locale-first t)
 '(ndspell-ispell-program "aspell -c")
 '(toolbar-mail-reader (quote vm))
 '(default-gutter-position (quote top))
 '(paren-highlight-offscreen t)
 '(mark-diary-entries-in-calendar t)
 '(view-diary-entries-initially t)
 '(no-redraw-on-reenter t)
 '(bbdb-default-label-list (quote ("Home" "Office" "Mobile" "Facs")))
 '(ndspell-process-coding-system (quote UTF-8))
 '(bbdb-check-zip-codes-p t)
 '(font-blink-interval 0.8)
 '(dictionary-default-popup-strategy "lev")
 '(ibuffer-dired-buffer-face (quote arial))
 '(colon-double-space t)
 '(sc-downcase-p t)
 '(mail-use-rfc822 t)
 '(mail-specify-envelope-from nil)
 '(dictionary-use-single-buffer t)
 '(paren-blink-interval 0.4)
 '(mail-archive-file-name "MailSent")
 '(font-lock-mode t nil (font-lock))
 '(sc-citation-leader "<    "))
(custom-set-faces
 '(default ((t (:size "12pt" :family "Fixed"))) t)
 '(info-xref ((t (:foreground "blue3" :background "white" :size "14" :bold t))))
 '(info-node ((t (:foreground "blue4" :background "yellow2" :size "14" :family "times" :bold t))))
 '(html-helper-italic-face ((t (:family "helvetica" :italic t))))
 '(dictionary-word-entry-face ((((type x)) (:foreground "green4" :size "16" :family "arial"))))
 '(html-helper-bold-face ((t (:background "white" :family "helvetica" :bold t))))
 '(arial ((t (:foreground "blue4" :size "14" :family "arial"))) t)
 '(paren-face-no-match ((((class color)) (:foreground "blue4" :background "coral" :size "16" :family "helvetica")))))

Spend some time doing the tutorials, it is time very well spent. In the meantime: Right clicking on things usually gives you some useful options. A buffer is a file living in memory only.

Now I have either saved you a LOT of time or confused you hopelessly. In the latter case I am very sorry. Restore the above files form your saved copies of the originals... you did that right :) and start xemacs again.

Explore the GUI and buffer interfaces to the configuration settings, they really are quite extensive (you can enter your latitude and longitude and have your sunrise sunset and day lengths for example, you can have yourself psychoanalysed and play games, write mail, etc etc... Emacsen are designed to run on a X powered graphical interface or from a real console (or even a virtual terminal, they take full advantage of Unix protocols and services... you may never need another application :) They are also huge and daunting interfaces, that can use lots of system resources if poorly configured. How far you take it is of course up to you.