{"id":1533,"date":"2020-04-20T12:00:33","date_gmt":"2020-04-20T10:00:33","guid":{"rendered":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/?p=1533"},"modified":"2020-04-20T15:10:24","modified_gmt":"2020-04-20T13:10:24","slug":"writing-avms-easily-in-latex-the-new-langsci-avm-package","status":"publish","type":"post","link":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/2020\/04\/20\/writing-avms-easily-in-latex-the-new-langsci-avm-package\/","title":{"rendered":"Writing AVMs easily in LaTeX: The new langsci-avm package"},"content":{"rendered":"<p>Attribute-value matrices, also known as feature structures, are used by various theories to describe linguistic objects and their complex properties. Among others, they are used in HPSG and LFG, and so several of the books submitted to Language Science Press depend on a comprehensive and user-friendly way to input them to LaTeX.<\/p>\n<div id=\"attachment_1541\" style=\"width: 594px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1541\" class=\"size-large wp-image-1541\" src=\"https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple-1024x255.png\" alt=\"\" width=\"584\" height=\"145\" srcset=\"https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple-1024x255.png 1024w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple-300x75.png 300w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple-768x191.png 768w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple-500x124.png 500w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple.png 1802w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><p id=\"caption-attachment-1541\" class=\"wp-caption-text\">An example structure created with <code>langsci-avm<\/code>. See the Section &#8220;Example 1&#8221; below for how to create this AVM.<\/p><\/div>\n<p>Our users almost always use the <code>avm<\/code> package or the extended <code>avm+<\/code>, of which an unkown amount of modified versions are circulated online. The original avm package is not a bad package at all, but it has not been updated for some years, which has led to problems. For example, some of the versions assume that the old font selection commands, <code>\\it<\/code>, <code>\\bf<\/code>, etc. are still used, <a href=\"https:\/\/texfaq.org\/FAQ-2letterfontcmd\" target=\"_blank\" rel=\"noopener\">which should be avoided in modern documents<\/a>.<!--more--><\/p>\n<p>So we decided to write a new package, <code>langsci-avm<\/code>. Our goal was to create a flexible and user-friendly interface with a beautiful visual output. Also, we wanted the package to be available on CTAN to ensure that there is a central place to obtain the package, and to enable users to file bug reports or contact the maintainer. If you want to dive into the package directly, <a href=\"https:\/\/ctan.org\/pkg\/langsci-avm\" target=\"_blank\" rel=\"noopener\">you can find it on CTAN<\/a> (including the user guide). If you are interested in the source code, please see our <a href=\"https:\/\/github.com\/langsci\/langsci-avm\" target=\"_blank\" rel=\"noopener\">public repository on GitHub.<\/a> This blog post provides examples that you can use for a quick start, and also some technical background.<\/p>\n<h1>Example 1: Basic syntax<\/h1>\n<p><code>langsci-avm<\/code> provides a command <code>\\avm<\/code>. In the scope of <code>\\avm<\/code>, delimiter characters are parsed to open and close (sub-)structures in a very natural way. Also, font selection is pre-configured to the typical HPSG appearance (which can be overwritten if necessary). Here&#8217;s an easy example and the code that produces it:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1541\" src=\"https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple-1024x255.png\" alt=\"\" width=\"584\" height=\"145\" srcset=\"https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple-1024x255.png 1024w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple-300x75.png 300w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple-768x191.png 768w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple-500x124.png 500w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/simple.png 1802w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/p>\n<pre>\\avm{\r\n       [ ctxt &amp; [ max-qud \\\\\r\n         sal-utt &amp; \\{ [ cat \\\\\r\n                            cont &lt;ind &amp; i&gt;\r\n                          ]\r\n                       \\}\r\n                     ]\r\n        ]\r\n}\r\n<\/pre>\n<p>Notice how delimiters are produced by their respective input symbols, with the braces being the only delimiters that need to be escaped, i.e. combined with the backslash. Line breaks and column separators are produced as usual in LaTeX, with <code>\\\\<\/code> and <code>&amp;<\/code>, respectively. The package automatically takes care of font selection: the content in the attribute column is typed in small caps, and the content of the value column in italics. The value column usually is the content after a <code>&amp;<\/code>, but every (sub-)structure created with a delimiter starts anew with the attribute column. Please see the documentation for font customisation. There&#8217;s a link to it at the end of this blog post.<\/p>\n<h1>Example 2: More elements, tags and relations<\/h1>\n<p>Relations like concatenation and tags can also be input easily with the package, as in this example, taken from Stefan M\u00fcller&#8217;s chapter <em>Constituent order<\/em> in an\u00a0upcoming HPSG handbook:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1539\" src=\"https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/order-1024x256.png\" alt=\"\" width=\"584\" height=\"146\" srcset=\"https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/order-1024x256.png 1024w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/order-300x75.png 300w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/order-768x192.png 768w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/order-500x125.png 500w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/order.png 1590w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/p>\n<pre>\\avm{\r\n\t[ phon &amp; \\1 \\+ \\ldots{} \\+ \\tag{n} \\\\\r\n\tdom  &amp; \r\n               &lt; [\\type*{sign} \r\n                  phon &amp; \\1 ], \\ldots, [\\type*{sign} \r\n                  phon &amp; \\tag{n} ] \r\n               &gt; ]\r\n}<\/pre>\n<p>In langsci-avm, tags and links are created with <code>\\1<\/code>, <code>\\2<\/code>, &#8230;, <code>\\9<\/code> for one-digit numbers, or with <code>\\tag{}<\/code> for a symbolic tag. Relations can also be input very easily: <code>\\+<\/code> is used in this example to express concatenation. <code>\\-<\/code> for subtraction and <code>\\shuffle<\/code> for the shuffle relation are available as well. The starred <code>\\type*{}<\/code> creates a line that spans both the attribute and value columns of the respective (sub-)structure and automatically places a line break afterwards. Types that do not span both columns can be input with the un-starred <code>\\type{}<\/code>. Please see the documentation, linked below, for a full description of available features.<\/p>\n<h1>Example 3: Relations between structures<\/h1>\n<p>Sometimes one wants to express mappings or disjunctions between multiple feature structures. To this end, langsci-avm integrates easily with the common LaTeX math relations:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-1543\" src=\"https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/relations-1024x74.png\" alt=\"\" width=\"584\" height=\"42\" srcset=\"https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/relations-1024x74.png 1024w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/relations-300x22.png 300w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/relations-768x55.png 768w, https:\/\/userblogs.fu-berlin.de\/langsci-press\/files\/2020\/03\/relations-500x36.png 500w\" sizes=\"auto, (max-width: 584px) 100vw, 584px\" \/><\/p>\n<pre>sign $\\to$ \\avm{ \r\n  [ attribute1 &amp; value1 ]\r\n  $\\lor$\r\n  [ attribute2 &amp; value2 ]\r\n}\r\n<\/pre>\n<h1>Installation<\/h1>\n<p>langsci-avm is on CTAN and available via the MikTeX, TeXLive, and MacTeX distributions. You&#8217;ll need an up-to-date TeXLive, MacTeX or MikTeX installation. If your installation is up to date, you can find and install the package under its name, <code>langsci-avm<\/code>, in both the TeX Live Manager and the MikTeX Console (in the &#8220;packages&#8221; tab).<\/p>\n<p>If you are on Linux and do not have the TeX Live Manager installed, you can install the package with:<\/p>\n<pre># Ubuntu and other distributions that use apt\r\nsudo apt-get install texlive-langsci-avm*\r\n# Fedora, SuSe, and other distributions with dnf\/yum\r\nsudo dnf install texlive-langsci-avm*<\/pre>\n<p>The wildcard <code>*<\/code> ensures that the documentation is also installed. If the documenation, available as <code>texlive-langsci-avm-doc<\/code>, is available on your system, you can open the documentation easily by issuing <code>texdoc langsci-avm<\/code> in the console.<\/p>\n<p>The package will also work with some older TeX distributions, in particular TeXLive 2019. To install the package locally, save the <a href=\"https:\/\/raw.githubusercontent.com\/langsci\/langsci-avm\/master\/langsci-avm.sty\" target=\"_blank\" rel=\"noopener\">.sty file<\/a> to the working directory of your current project.<\/p>\n<p>With the package installed or the .sty file saved, you can use it in your documents with a simple <code>\\usepackage{langsci-avm}<\/code> in your preamble.<\/p>\n<h1>Technical background<\/h1>\n<p><code>langsci-avm<\/code> shares no code base with the original <code>avm<\/code> package, and their designs are fundamentally different. The original <code>avm<\/code> package had two modes, active and passive. In the active mode, the <a href=\"https:\/\/texfaq.org\/FAQ-activechars\" target=\"_blank\" rel=\"noopener\">category code of the delimiters was changed<\/a> so that they could be used as commands. Since at that time this procedure implied some usage restrictions, a passive mode was introduced in which delimiters had to be input as <code>\\[<\/code> or <code>\\(<\/code> , etc. Depending on the user&#8217;s keyboard layout and the respective position of <code>\\<\/code>, this wasn&#8217;t fun at all. It also turned out to be unsatisfactory for two other reasons. First, the active mode had the desired user input, because the user did not have to type a backslash every time they wanted to open or close a (sub-)structure, but one could not use it in situations like a syntactic tree or a footnote (placing large objects like AVMs in footnotes is almost always a bad idea, anyway). Second, it made collaboration quite difficult, since different users had different preferences whether to use the active or passive mode, but they can&#8217;t be used simultaneously in the same document. If one then decided to use the passive mode to increase compatibility, one had to re-type their AVMs so they included the backslash for every single (sub-)structure.<\/p>\n<p>In langsci-avm we decided to <em>parse<\/em> the code, which is another method besides changing character codes (the approach in the old active mode) or defining commands (the approach in the old passive mode). This way, we do not have to worry about character codes, and we can still process delimiters without having to mark them with backslashes. The sole and important exception being curly braces, due to their important meaning in LaTeX as group characters.<\/p>\n<p>At the time of LaTeX 2.09, when the original <code>avm<\/code> was written, parsing was a quite difficult matter. But the situation has since improved drastically due to the release of <a href=\"https:\/\/www.latex-project.org\/latex3\/\" target=\"_blank\" rel=\"noopener\">LaTeX3<\/a>. LaTeX3 offers a whole array of programming interfaces to easily manage data such as booleans, data, key-value pairs, and it provides a very usable, if still somehow idiosyncratic, recursion function (called <em>quarks<\/em> in LaTeX3-speak). So besides parsing, we will be able to offer many more features, such as a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Stack_(abstract_data_type)\" target=\"_blank\" rel=\"noopener\">stack<\/a> to check whether the user did input a balanced set of delimiters, and then supply a detailed error message when they haven&#8217;t (this is a planned feature).<\/p>\n<p>Internally, the same plain TeX code is executed, but the pre-configured routines of LaTeX3 take care of many internals that would otherwise require vast experience. That is particularly true for the matter of expansion control, which is the main reason why parsing was so difficult in LaTeX 2.09.<\/p>\n<hr \/>\n<p><em>Thanks to Phelype Oleinik for help on recursion and expansion with LATEX3. Thanks to Ahmet Bilal \u00d6zdemir and Stefan M\u00fcller for their contributions in planning and testing<\/em><br \/>\n<em>this package.<\/em><\/p>\n<p>Comments on the current version, which is still in beta, are most welcome. To do so, please <a href=\"https:\/\/github.com\/langsci\/langsci-avm\/issues\">open an issue in the GitHub repository.<\/a><\/p>\n<p>The documentation, which describes all the features, commands, and customisation options of the package, can be found on <a href=\"https:\/\/github.com\/langsci\/langsci-avm\/blob\/master\/langsci-avm.pdf\" target=\"_blank\" rel=\"noopener\">GitHub<\/a> or <a href=\"http:\/\/mirrors.ctan.org\/macros\/latex\/contrib\/langsci-avm\/langsci-avm.pdf\" target=\"_blank\" rel=\"noopener\">CTAN<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Attribute-value matrices, also known as feature structures, are used by various theories to describe linguistic objects and their complex properties. Among others, they are used in HPSG and LFG, and so several of the books submitted to Language Science Press &hellip; <a href=\"https:\/\/userblogs.fu-berlin.de\/langsci-press\/2020\/04\/20\/writing-avms-easily-in-latex-the-new-langsci-avm-package\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4717,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[68809,1150],"tags":[],"class_list":["post-1533","post","type-post","status-publish","format-standard","hentry","category-author","category-latex"],"_links":{"self":[{"href":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/wp-json\/wp\/v2\/posts\/1533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/wp-json\/wp\/v2\/users\/4717"}],"replies":[{"embeddable":true,"href":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/wp-json\/wp\/v2\/comments?post=1533"}],"version-history":[{"count":32,"href":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/wp-json\/wp\/v2\/posts\/1533\/revisions"}],"predecessor-version":[{"id":1569,"href":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/wp-json\/wp\/v2\/posts\/1533\/revisions\/1569"}],"wp:attachment":[{"href":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/wp-json\/wp\/v2\/media?parent=1533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/wp-json\/wp\/v2\/categories?post=1533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/userblogs.fu-berlin.de\/langsci-press\/wp-json\/wp\/v2\/tags?post=1533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}