{"id":747,"date":"2021-07-21T13:01:20","date_gmt":"2021-07-21T13:01:20","guid":{"rendered":"http:\/\/www.jontrinder.com\/blog\/?p=747"},"modified":"2021-07-21T13:03:36","modified_gmt":"2021-07-21T13:03:36","slug":"lyx-configuration-fails-when-new-layouts-added","status":"publish","type":"post","link":"https:\/\/www.jontrinder.com\/blog\/?p=747","title":{"rendered":"Lyx Configuration Fails When new Layouts Added"},"content":{"rendered":"\n<p>Added something to lyx, clicked reconfigure and you get the news that &#8220;reconfiguration failed&#8230;.&#8221;.<\/p>\n\n\n\n<p>Been there done that, got the  errors and much sadness. So This post is a quick a)reminder to me what I did, b)some notes to help others fix\/debug similar problems.<\/p>\n\n\n\n<p>I&#8217;d just added these book links from editorium from the link for book layouts  at <a href=\"https:\/\/wiki.lyx.org\/Layouts\/Layouts\" data-type=\"URL\" data-id=\"https:\/\/wiki.lyx.org\/Layouts\/Layouts\">https:\/\/wiki.lyx.org\/Layouts\/Layouts<\/a><\/p>\n\n\n\n<p>Which provides new layout files ( LyXBook&#8211;Default.layout and LyXBook&#8211;Archaic.layout ) which have to be  placed in \/usr\/share\/lyx\/layouts folder.  Once done you need to tell lyx to reconfigure (Tools-Reconfigure). But at that point I got an error  message like  this:-<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n<style type=\"text\/css\">p, li { white-space: pre-wrap; }<\/style><p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">The system reconfiguration has failed.Default textclass is used but LyX maynot be able to work properly.Please reconfigure again if needed.<\/p><\/code><\/pre>\n\n\n\n<p>Although fairly obvious what had broken the setup was the new layout files, Ithough it would be useful to document how you can debug this type of problem.<\/p>\n\n\n\n<p>Launch Lyx from command line so you can see error messages<\/p>\n\n\n\n<p>This gave some clues.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Traceback (most recent call last):  \nFile \"\/usr\/share\/lyx\/configure.py\", line 1901, in &lt;module&gt;   \n ret = checkLatexConfig(lyx_check_config and LATEX, bool_docbook) \nFile \"\/usr\/share\/lyx\/configure.py\", line 1422, in checkLatexConfig    \n for line in open(file, 'r', encoding='utf8').readlines():  \nFile \"\/usr\/lib\/python3.8\/codecs.py\", line 322, in decode    \n (result, consumed) = self._buffer_decode(data, self.errors, final)\nUnicodeDecodeError: 'utf-8' codec can't decode byte 0xa9 in position 845: invalid start byte\nsupport\/Systemcall.cpp (276): Systemcall: 'python3 -tt \"\/usr\/share\/lyx\/configure.py\" --binary-dir=\"\/usr\/bin\/\"' finished with exit code 1\n<\/code><\/pre>\n\n\n\n<p>The immediate clue is in one of the files there is something that was expected to be an utf-8 encoded character, but wasnt. Now need to find it&#8230;..We have only added two layout files so they are where the problem lies, but which line of which file?<\/p>\n\n\n\n<p>Now just in case you have added lots of layout and want to identify the specific file you can modify the python script as explained at <a href=\"https:\/\/www.lyx.org\/trac\/ticket\/11736\">https:\/\/www.lyx.org\/trac\/ticket\/11736<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>modify \/usr\/share\/lyx\/configure.py around line 1420 which looks like this\ncatline = \"\"        \nfor line in open(file, 'r', encoding='utf8').readlines()\n<\/code><\/pre>\n\n\n\n<p>add an extra line so it looks liek this instead. Its Python so be careful with those indents  <a href=\"https:\/\/www.google.com\/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;cad=rja&amp;uact=8&amp;ved=2ahUKEwjzmLr0lvTxAhVrRkEAHbFnAQsQwqsBegQICRAB&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DSsoOG6ZeyUI&amp;usg=AOvVaw0HG-y5H25bKq859qtZqn9W\">spaces vs tabs<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>catline = \"\"        \nlogger.info(\"class: \" + classname)       \nfor line in open(file, 'r', encoding='utf8').readlines()<\/code><\/pre>\n\n\n\n<p>Then tell Lyx to reconfigure again, the difference being we now get told which file had the problem.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class: LyXBook--Default\nTraceback (most recent call last):  \nFile \"\/usr\/share\/lyx\/configure.py\", line 1901, in &lt;module&gt;   \n ret = checkLatexConfig(lyx_check_config and LATEX, bool_docbook) \nFile \"\/usr\/share\/lyx\/configure.py\", line 1422, in checkLatexConfig    \n for line in open(file, 'r', encoding='utf8').readlines():  \nFile \"\/usr\/lib\/python3.8\/codecs.py\", line 322, in decode    \n (result, consumed) = self._buffer_decode(data, self.errors, final)\nUnicodeDecodeError: 'utf-8' codec can't decode byte 0xa9 in position 845: invalid start byte\nsupport\/Systemcall.cpp (276): Systemcall: 'python3 -tt \"\/usr\/share\/lyx\/configure.py\" --binary-dir=\"\/usr\/bin\/\"' finished with exit code 1\n<\/code><\/pre>\n\n\n\n<p>Well that confimed a few things the file is LyXBook&#8211;Default, and the error related to unicode\/utf-8.<\/p>\n\n\n\n<p>So lets find where the non utf-8 characters are in the layout files.<\/p>\n\n\n\n<p>For this need a little grep incantation and explained here <\/p>\n\n\n\n<p>(as shown by Pablo Bianchi at <a href=\"https:\/\/stackoverflow.com\/questions\/29465612\/how-to-detect-invalid-utf8-unicode-binary-in-a-text-file\">https:\/\/stackoverflow.com\/questions\/29465612\/how-to-detect-invalid-utf8-unicode-binary-in-a-text-file<\/a>)<\/p>\n\n\n\n<p>Which says<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -axv '.*' LyXBook--Default.layout     \n\nthe arguments here are \n-a, --text: treats file as text, essentialy prevents grep to abort once finding an invalid byte sequence (not being utf8)    \n-v, --invert-match: inverts the output showing lines not matched    \n-x '.*' (--line-regexp): means to match a complete line consisting of any utf8 character.<\/code><\/pre>\n\n\n\n<p>So lets run the command<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -axv '.*' LyXBook--Default.layout \n# LyXBook layouts, modules, and documentation copyright \ufffd 2013 by the Editorium. All rights reserved.\n# LyXBook\ufffd is a trademark of the Editorium:<\/code><\/pre>\n\n\n\n<p>You can spot the non utf-8<\/p>\n\n\n\n<p>And you can see which lines have something non utf-8 in them.<\/p>\n\n\n\n<p>So you can now go and remove those characters, reconfigure Lyx and and all will be happiness&#8230;.ish<code role=\"textbox\" aria-multiline=\"true\" aria-label=\"Code\" class=\"block-editor-rich-text__editable rich-text\" contenteditable=\"true\"><pre class=\"block-editor-block-list__block wp-block is-selected wp-block-code\" id=\"block-de0936a7-8e5f-4c57-a28b-49d01372537d\" tabindex=\"0\" role=\"group\" aria-label=\"Block: Code\" data-block=\"de0936a7-8e5f-4c57-a28b-49d01372537d\" data-type=\"core\/code\" data-title=\"Code\" style=\"\"><code role=\"textbox\" aria-multiline=\"true\" aria-label=\"Code\" class=\"block-editor-rich-text__editable rich-text\" style=\"white-space: pre-wrap; min-width: 1px;\" contenteditable=\"true\"><\/code><\/pre><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Added something to lyx, clicked reconfigure and you get the news that &#8220;reconfiguration failed&#8230;.&#8221;. Been there done that, got the errors and much sadness. So This post is a quick a)reminder to me what I did, b)some notes to help &hellip; <a href=\"https:\/\/www.jontrinder.com\/blog\/?p=747\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[119,59],"class_list":["post-747","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-latex","tag-lyx"],"_links":{"self":[{"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=747"}],"version-history":[{"count":9,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/747\/revisions"}],"predecessor-version":[{"id":756,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/747\/revisions\/756"}],"wp:attachment":[{"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jontrinder.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}