1 #LyX 2.4 created this file. For more info see https://www.lyx.org/
5 \save_transient_properties true
6 \origin /systemlyxdir/doc/
8 \options BCOR8mm,captions=tableheading
9 \use_default_options false
13 \maintain_unincluded_children no
15 \language_package default
18 \font_roman "lmodern" "default"
19 \font_sans "lmss" "default"
20 \font_typewriter "lmtt" "default"
21 \font_math "auto" "auto"
22 \font_default_family default
23 \use_non_tex_fonts false
27 \font_typewriter_osf false
28 \font_sf_scale 100 100
29 \font_tt_scale 100 100
31 \use_dash_ligatures true
33 \default_output_format pdf2
35 \bibtex_command default
36 \index_command default
37 \float_placement class
38 \float_alignment class
42 \pdf_title "LyX's Development manual"
43 \pdf_author "LyX Team"
44 \pdf_subject "LyX's development documentation"
45 \pdf_keywords "LyX, Documentation, Development"
47 \pdf_bookmarksnumbered true
48 \pdf_bookmarksopen true
49 \pdf_bookmarksopenlevel 1
54 \pdf_pdfusetitle false
55 \pdf_quoted_options "linkcolor=black, citecolor=black, urlcolor=blue, filecolor=blue, pdfpagelayout=OneColumn, pdfnewwindow=true, pdfstartview=XYZ, plainpages=false"
58 \use_package amsmath 1
59 \use_package amssymb 1
62 \use_package mathdots 1
63 \use_package mathtools 1
65 \use_package stackrel 1
66 \use_package stmaryrd 1
67 \use_package undertilde 1
69 \cite_engine_type default
73 \paperorientation portrait
79 \notefontcolor #0000ff
86 \paragraph_separation indent
87 \paragraph_indentation default
89 \math_numbering_side default
94 \paperpagestyle headings
96 \tracking_changes false
99 \postpone_fragile_content false
103 \docbook_table_output 0
109 Developing \SpecialChar LyX
113 \begin_layout Subtitle
118 by the \SpecialChar LyX
123 \begin_layout Plain Layout
125 If you have comments or error corrections, please send them to the \SpecialChar LyX
128 \begin_inset Flex Code
131 \begin_layout Plain Layout
132 <lyx-docs@lists.lyx.org>
145 \begin_layout Standard
146 \begin_inset CommandInset toc
147 LatexCommand tableofcontents
154 \begin_layout Chapter
158 \begin_layout Standard
159 This manual documents some aspects of \SpecialChar LyX
161 It is currently rather incomplete, but will hopefully be extended in the
163 Meanwhile, additional information can be found in the
164 \begin_inset Flex Code
167 \begin_layout Plain Layout
173 subfolder of the \SpecialChar LyX
174 source code distribution.
175 This document is not translated, since the development language of \SpecialChar LyX
178 If you just want to use \SpecialChar LyX
179 , then you don't need to read this manual.
180 However, if you want to learn more about how \SpecialChar LyX
181 is developed, or even want
182 to participate in \SpecialChar LyX
183 development, you may find some interesting information
187 \begin_layout Chapter
191 \begin_layout Standard
193 uses several custom file formats for configuration files and documents.
194 This chapter contains some background concerning these file formats.
195 Several file formats are also described in detail in the regular user documenta
199 \begin_layout Section
203 \begin_layout Section
204 When is an update of the .lyx file format number needed?
205 \begin_inset CommandInset label
207 name "sec:When-is-an"
214 \begin_layout Standard
215 When you are working on a new feature you may ask yourself whether it needs
216 an update of the .lyx file format number.
217 Whether an update is needed or not is not always obvious.
222 Whenever there is the danger that a previous version of LyX cannot open
223 a file using the new feature, a file format update is needed.
226 \begin_layout Standard
227 The file format change allows lyx2lyx rules to implement backwards compatibility.
228 Below you can find a list of reasons for file format updates with explanations:
231 \begin_layout Description
240 setting Whenever you introduce a new setting that is stored in the document
241 header, a file format update is needed.
244 \begin_layout Description
253 setting If a certain setting becomes obsolete and gets removed, a file format
257 \begin_layout Description
283 \begin_inset space \thinspace{}
290 \begin_layout Description
291 \paragraph_spacing single
304 package The reason for this is that there is no true ERT inset for math
305 formulas: Each command is parsed, and if a user happens to define a local
306 command with the same name as a command that triggers an automatic load
307 of a package, they need to be able to switch off the automatic loading
309 This switch is stored by the
310 \begin_inset Flex Code
313 \begin_layout Plain Layout
322 \begin_layout Description
327 language that is stored in
328 \begin_inset Flex Code
331 \begin_layout Plain Layout
341 \begin_inset Note Note
344 \begin_layout Plain Layout
345 This requirement is under discussion.
354 \begin_layout Description
359 inset Of course a new inset requires a file format update.
362 \begin_layout Description
367 style If a new style or inset layout is added to any layout file or module
368 shipped with \SpecialChar LyX
369 , then a new file format is needed in the master (development)
371 It is possible to backport new styles to the stable version without a file
374 \begin_inset CommandInset ref
376 reference "subsec:Backporting-new-styles"
380 for more information.
383 \begin_layout Description
388 style If a style or inset layout is removed in any layout file or module
389 shipped with \SpecialChar LyX
390 , a new file format is required.
393 \begin_layout Standard
398 layouts and modules do
402 require a file format update (changed 03/16, see
403 \begin_inset CommandInset ref
405 reference "subsec:New-layouts"
413 \begin_layout Standard
414 If you are still unsure, please ask on the development list.
417 \begin_layout Section
418 \begin_inset CommandInset label
420 name "subsec:update_lyx_files"
424 How to update the file format number of .lyx files
427 \begin_layout Standard
428 Once you come to the conclusion that a file format update is needed, you
429 should use the following procedure to perform the update:
432 \begin_layout Enumerate
433 Implement and test the new feature, including the reading and writing of
435 Note that any file produced at this stage does not use a valid format,
436 so do not use this version of \SpecialChar LyX
437 for working on any important documents.
440 \begin_layout Enumerate
441 \begin_inset CommandInset label
443 name "enu:Describe_format"
447 Describe the new format in
448 \begin_inset Flex Code
451 \begin_layout Plain Layout
460 \begin_layout Enumerate
461 Update the \SpecialChar LyX
462 file format number in
463 \begin_inset Flex Code
466 \begin_layout Plain Layout
475 \begin_layout Enumerate
476 \begin_inset CommandInset label
478 name "enu:Add-an-entry"
482 Add an entry to both format lists (for conversion and reversion) in
483 \begin_inset Newline newline
487 \begin_inset Flex Code
490 \begin_layout Plain Layout
491 lib/lyx2lyx/lyx_2_4.py
497 Add a conversion routine if needed (e.
498 \begin_inset space \thinspace{}
501 g., a new header setting always needs a conversion that adds the new setting,
502 but a new document language does not need one).
503 Add a reversion routine if needed.
505 \begin_inset Newline newline
508 While the conversion routine is required to produce a document that is equivalen
509 t to the old version, the requirements of the reversion are not that strict.
510 If possible, try to produce a proper reversion, using ERT if needed, but
511 for some features this might be too complicated.
512 In this case, the minimum requirement of the reversion routine is that
513 it produces a valid document which can be read by an older \SpecialChar LyX
515 If absolutely needed, even data loss is allowed for the reversion.
516 (In that case, you might want to add a LyX comment that indicates what
517 you have had to do, so the user is at least warned).
520 \begin_layout Enumerate
521 Since tex2lyx has several implicit file format dependencies caused by sharing
522 code with \SpecialChar LyX
523 , updating the file format of .lyx files produced by tex2lyx at
524 the same time as updating the main .lyx file format is strongly recommended.
525 Therefore, a compiler warning will be issued if the \SpecialChar LyX
526 and tex2lyx .lyx file
527 format numbers differ.
528 In many cases the tex2lyx update requires only the first and last item
533 \begin_layout Enumerate
534 Update the tex2lyx file format number in
535 \begin_inset Flex Code
538 \begin_layout Plain Layout
547 \begin_layout Enumerate
548 If the lyx2lyx conversion from the old to the new format is empty, or if
549 tex2lyx does not yet output the changed feature, you do not need any further
551 Otherwise, search for the changed feature in tex2lyx, and adjust the output
552 according to the lyx2lyx changes.
555 \begin_layout Enumerate
556 Update the tex2lyx test references as described in
557 \begin_inset CommandInset ref
558 LatexCommand formatted
559 reference "sec:Updating-test-references"
567 \begin_layout Enumerate
568 If you did not implement full tex2lyx support for the new feature, add a
570 \begin_inset Flex Code
573 \begin_layout Plain Layout
579 describing the missing bits.
580 Note that it is perfectly fine if you do not add full tex2lyx support for
581 a new feature: The updating recommendation above is only issued for the
582 syntax of the produced .lyx file.
583 It is no problem if some features supported by \SpecialChar LyX
584 are still output as ERT
586 The problems in the past that resulted in the update recommendation were
587 related to mixed version syntax, not ERT.
590 \begin_layout Enumerate
591 It would be nice if you could create a .lyx test file which contains instances
592 of all changed or added features.
593 This could then be used to test lyx2lyx and tex2lyx.
594 Test samples are collected under the corresponding subdirectories of
601 \begin_layout Enumerate
602 \begin_inset CommandInset label
604 name "enu:updatefiles"
608 Test your lyx2lyx code by updating LyX's .lyx documentation files to the
610 The developer who makes the change knows best what changes to expect when
611 inspecting the resulting diff.
612 Because of this, you might be able to catch a bug in the lyx2lyx code that
613 updates the format just by taking a quick scan through the large diff that
615 \begin_inset Note Note
618 \begin_layout Plain Layout
619 Another advantage is that if later we suspect a bug in lyx2lyx we can easily
620 see which layout update made an unexpected change by looking at the git
621 log of a .lyx file that suffers the problem.
626 To do this, first make sure that there are no changes to the git repository
627 that you will not want to commit (this is needed because it will be convenient
628 to commit with the command
629 \begin_inset Flex Code
632 \begin_layout Plain Layout
639 Then run the following command in the root folder of the source:
640 \begin_inset Flex Code
643 \begin_layout Plain Layout
644 python development/tools/updatedocs.py
650 Look at the resulting changes using the command
651 \begin_inset Flex Code
654 \begin_layout Plain Layout
661 If anything looks surprising, please investigate.
662 Keep in mind that the case of
663 \begin_inset Flex Code
666 \begin_layout Plain Layout
672 is special, because it is first generated with
673 \begin_inset Flex Code
676 \begin_layout Plain Layout
682 before being converted to the latest format.
683 \begin_inset Newline newline
687 \begin_inset Note Greyedout
690 \begin_layout Plain Layout
695 Only commit file format changes in the doc files if these files are using
696 the new feature of the new file format.
702 \begin_inset CommandInset ref
704 reference "enu:The-fileformat-of"
708 of the documentation policies described in sec.
713 \begin_inset CommandInset ref
715 reference "sec:Documentation-policies"
727 \begin_layout Enumerate
728 Finally, commit using
729 \begin_inset Flex Code
732 \begin_layout Plain Layout
741 \begin_layout Section
742 Updating the file format number of layout files
745 \begin_layout Standard
746 The procedure for updating the layout files is similar to that in step
747 \begin_inset CommandInset ref
749 reference "enu:updatefiles"
754 \begin_inset CommandInset ref
756 reference "subsec:update_lyx_files"
762 \begin_inset Flex Code
765 \begin_layout Plain Layout
766 python development/tools/updatelayouts.py
772 \begin_inset Flex Code
775 \begin_layout Plain Layout
784 \begin_layout Standard
785 Note that we do not automatically update any local layout used in the
786 \begin_inset Flex Code
789 \begin_layout Plain Layout
795 files shipped with \SpecialChar LyX
796 because users would then not be able to export to older
798 For example, if a 2.2.0 user exported a template to 2.1.x format and tried
799 to open the file in \SpecialChar LyX
800 2.1.x, there would be an error because the file would
801 contain a local layout whose format is too new.
802 The root reason for this is that we do not support converting layouts to
803 older layout formats, as we do for the
804 \begin_inset Flex Code
807 \begin_layout Plain Layout
816 \begin_layout Section
817 Updating the file format number of bind/ui files
820 \begin_layout Standard
821 A change to the functionality of existing LFUNs can require a conversion
823 \begin_inset Flex Code
826 \begin_layout Plain Layout
833 \begin_inset Flex Code
836 \begin_layout Plain Layout
842 files, and therefore an increment of the LFUN format, as well as a conversion
844 \begin_inset Flex Code
847 \begin_layout Plain Layout
854 The latter cannot be done automatically and also requires an update of
858 \begin_inset space \space{}
861 of someone who might have made a set of \SpecialChar LyX
862 teaching manuals for use in their
867 \begin_layout Plain Layout
868 \begin_inset Flex URL
871 \begin_layout Plain Layout
873 https://www.lyx.org/trac/ticket/9794
886 \begin_layout Standard
887 To update the LFUN format:
890 \begin_layout Enumerate
891 Increment the LFUN file format number in
892 \begin_inset Flex Code
895 \begin_layout Plain Layout
904 \begin_layout Enumerate
905 Implement the LFUN conversion in
906 \begin_inset Flex Code
909 \begin_layout Plain Layout
910 lib/scripts/prefs2prefs_lfuns.py
918 \begin_layout Enumerate
920 \begin_inset CommandInset ref
922 reference "enu:updatefiles"
927 \begin_inset CommandInset ref
929 reference "subsec:update_lyx_files"
934 \begin_inset Flex Code
937 \begin_layout Plain Layout
943 command, use this command:
944 \begin_inset Flex Code
947 \begin_layout Plain Layout
948 bash development/tools/updatelfuns.sh
955 \begin_inset Note Note
958 \begin_layout Plain Layout
959 This file should really be converted to python.
967 \begin_layout Enumerate
968 Update Info insets in
969 \begin_inset Flex Code
972 \begin_layout Plain Layout
979 To do so, increment the \SpecialChar LyX
980 format and proceed as in
981 \begin_inset CommandInset ref
983 reference "subsec:update_lyx_files"
988 \begin_inset CommandInset ref
990 reference "enu:Describe_format"
995 \begin_inset CommandInset ref
997 reference "enu:updatefiles"
1002 In the lyx2lyx implementation (step
1003 \begin_inset CommandInset ref
1005 reference "enu:Add-an-entry"
1009 ), implement a conversion similar to the one in
1010 \begin_inset Flex Code
1013 \begin_layout Plain Layout
1014 prefs2prefs_lfuns.py
1019 above, as well as a corresponding reversion; for this one can use
1020 \begin_inset Flex Code
1023 \begin_layout Plain Layout
1030 \begin_inset Flex Code
1033 \begin_layout Plain Layout
1034 lib/lyx2lyx/lyx2lyx_tools.py
1043 \begin_layout Section
1044 Backporting new styles to the stable version
1045 \begin_inset CommandInset label
1047 name "subsec:Backporting-new-styles"
1054 \begin_layout Standard
1055 Starting with the stable \SpecialChar LyX
1056 2.1 branch, there is a mechanism in place to backport
1057 new styles to the stable version without the need to update the file format.
1058 The basic idea is that the new style definition is automatically copied
1059 to the document preamble so that it can even be used by older minor versions
1060 that did not yet include the style.
1061 To backport a new style to the stable version, the following steps are
1065 \begin_layout Enumerate
1067 \begin_inset Flex Code
1070 \begin_layout Plain Layout
1076 to the style definition in the development version.
1079 \begin_layout Enumerate
1080 Copy the style definition to the stable version, but use
1081 \begin_inset Flex Code
1084 \begin_layout Plain Layout
1091 If needed adjust the format to the one used by the stable version (see
1092 the customization manual for details of the layout file format).
1095 \begin_layout Enumerate
1096 For each update of the style in a later stable version, increase the argument
1098 \begin_inset Flex Code
1101 \begin_layout Plain Layout
1108 (In the stable version, the development version should not be touched.)
1111 \begin_layout Standard
1112 For details about the
1113 \begin_inset Flex Code
1116 \begin_layout Plain Layout
1122 flag see the customization manual.
1124 \begin_inset Flex Code
1127 \begin_layout Plain Layout
1133 support is needed for backported styles: Since the style of the development
1134 version has an infinite version number, it will always be used.
1135 Furthermore, since its version number is less than one, the style will
1136 not be written anymore to the document header for files saved by the new
1140 \begin_layout Chapter
1141 New layouts and modules
1144 \begin_layout Section
1145 \begin_inset CommandInset label
1147 name "subsec:New-layouts"
1154 \begin_layout Standard
1155 Adding a new layout file to the \SpecialChar LyX
1157 \begin_inset Quotes eld
1160 officially supported
1161 \begin_inset Quotes erd
1165 You should therefore think carefully about whether you really want to do
1166 this and discuss it on lyx-devel, since you will need to be prepared to
1167 update and fix the layout if necessary.
1168 If the layout is experimental or for a rarely used document class, then
1169 it may be better to add it to the relevant portion of the \SpecialChar LyX
1173 \begin_inset CommandInset href
1175 target "https://wiki.lyx.org/Layouts/Layouts"
1183 \begin_layout Standard
1184 In older versions of this document, it was stated that new layout files
1185 require a file format change.
1186 After some discussion, it was decided that this is not needed.
1190 \begin_layout Plain Layout
1192 \begin_inset CommandInset href
1194 name "the thread “Proposal for a guide on updating layouts”"
1195 target "http://permalink.gmane.org/gmane.editors.lyx.devel/161202"
1209 For reference, here are the arguments on each side
1213 \begin_layout Description
1215 \begin_inset Quotes eld
1218 New layout files are a file format change
1219 \begin_inset Quotes erd
1225 \begin_layout Itemize
1226 All documents produced by 2.2.
1227 \begin_inset Formula $x$
1230 can always be edited and exported even if
1231 \begin_inset Formula $x$
1235 This is important for people using different machines, or exchanging work
1239 \begin_layout Description
1241 \begin_inset Quotes eld
1244 New layout files are not a file format change
1245 \begin_inset Quotes erd
1251 \begin_layout Itemize
1252 No new LaTeX classes can be supported in a stable version, and stable versions
1253 have a typical lifetime of 2–3 years.
1256 \begin_layout Itemize
1257 We have the same situation already with custom layout files: If a document
1258 using a custom layout file is moved between machines or people, then the
1259 layout file needs to be exchanged as well.
1260 If that is not done, then we have a fallback implemented so that such documents
1261 can still be edited, but not exported, and the user gets a warning.
1265 \begin_layout Itemize
1266 The lyx2lyx script cannot do anything useful in such a case.
1270 \begin_layout Standard
1271 If you have decided that you are going to add a new layout file to \SpecialChar LyX
1273 then, you should do the following:
1276 \begin_layout Enumerate
1277 Put your new layout file in
1278 \begin_inset Flex Code
1281 \begin_layout Plain Layout
1288 \begin_inset Flex Code
1291 \begin_layout Plain Layout
1292 git add lib/layouts/newlayout.layout
1297 ) so that it will be committed.
1300 \begin_layout Enumerate
1302 \begin_inset Flex Code
1305 \begin_layout Plain Layout
1311 , so that the new layout actually gets installed.
1314 \begin_layout Enumerate
1316 \begin_inset Flex Code
1319 \begin_layout Plain Layout
1320 lib/doc/LaTeXConfig.lyx
1325 containing in particular a line like
1333 \begin_layout Standard
1334 where [InsetInfo] is obtained by entering in the minibuffer (Alt+X)
1335 \begin_inset Flex Code
1338 \begin_layout Plain Layout
1339 info-insert textclass <name>
1345 This inset will automatically display a boxed
1346 \begin_inset Quotes eld
1350 \begin_inset Quotes erd
1354 \begin_inset Quotes eld
1358 \begin_inset Quotes erd
1361 depending on the availability of the package.
1365 \begin_layout Enumerate
1366 A template or example is strongly encouraged (but not necessarily required).
1367 It is also possible to provide both.
1369 \begin_inset Flex Code
1372 \begin_layout Plain Layout
1379 \begin_inset Flex Code
1382 \begin_layout Plain Layout
1391 \begin_layout Enumerate
1392 Reconfigure \SpecialChar LyX
1396 \begin_layout Enumerate
1397 Ensure the autotests for the new layout pass (see
1398 \begin_inset CommandInset ref
1400 reference "par:when-to-run-an-export-test"
1407 \begin_layout Section
1411 \begin_layout Standard
1412 Adding a new module is very similar to adding a new layout.
1413 Therefore, the previous section applies to new modules as well, with two
1417 \begin_layout Enumerate
1418 You only need to add an entry to
1419 \begin_inset Flex Code
1422 \begin_layout Plain Layout
1423 lib/doc/LaTeXConfig.lyx
1428 if the module requires a LaTeX package.
1429 In that case, the command for entering the InsetInfo is:
1430 \begin_inset Flex Code
1433 \begin_layout Plain Layout
1434 info-insert package <name>
1442 \begin_layout Enumerate
1443 Modules do not need a template, only an example, which is strongly encouraged
1444 but not necessarily required.
1447 \begin_layout Section
1448 Layouts for document classes with incompatible versions
1451 \begin_layout Standard
1452 \begin_inset Note Greyedout
1455 \begin_layout Description
1456 Note: This section is currently only a proposal under discussion.
1457 Please correct/amend as suited.
1458 Remove this note once a consensus is found.
1461 \begin_layout Plain Layout
1463 \begin_inset Quotes eld
1466 Proposal for a guide on updating layouts
1467 \begin_inset Quotes erd
1470 for details and background
1473 \begin_layout Plain Layout
1474 http://permalink.gmane.org/gmane.editors.lyx.devel/161126
1482 \begin_layout Standard
1483 Every now and then, there are changes to LaTeX document classes that break
1484 backwards compatibility.
1488 \begin_layout Plain Layout
1489 Uwe has suggested we implement automatic detection of changes in class files.
1490 This could be done by running a script every month that checks if a document
1491 class was changed at CTAN and at the homepages of the scientific journals.
1492 If it reports a change, we can check if our template and layout file are
1493 still usable with the changed document class.
1494 (This is different from the autotests insofar, as this would also catch
1495 changes that do not result in compilation errors.)
1500 Reasons can be a new name for the
1501 \begin_inset Flex Code
1504 \begin_layout Plain Layout
1510 file, removed \SpecialChar LaTeX
1512 How should this best be handled in \SpecialChar LyX
1516 \begin_layout Standard
1517 The idea is to support the new version with a new \SpecialChar LyX
1521 \begin_layout Itemize
1522 Existing documents can still be opened in \SpecialChar LyX
1523 and will continue to work on
1524 systems where the old version is still installed.
1528 \begin_layout Itemize
1529 With differently named
1530 \begin_inset Flex Code
1533 \begin_layout Plain Layout
1539 files, \SpecialChar LyX
1540 can check for the availability of the particular version and reflect
1542 Different document class versions with the same file name are currently
1543 (2.2.x) not detected by the configuration script.
1544 This is planned for 2.3.
1548 \begin_layout Plain Layout
1549 https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg192467.html
1552 \begin_layout Plain Layout
1553 However, what we really need is version detection for the configuration,
1554 so that the user can be warned if the required class file has the wrong
1556 (If the class file keeps the name over the version change, only one of
1557 the two layout files generates compilable documents.)
1560 \begin_layout Plain Layout
1561 This point was also made here: http://permalink.gmane.org/gmane.editors.lyx.devel/143
1570 \begin_layout Itemize
1571 The new layout can be added both to the master and the stable branches,
1572 in accord with the policy discussed in
1573 \begin_inset CommandInset ref
1574 LatexCommand formatted
1575 reference "subsec:New-layouts"
1580 No lyx2lyx conversion is then required when a new major version is released.
1583 \begin_layout Standard
1584 The user can move an existing document to the new version simply by selecting
1585 a new document class.
1586 This step is well supported by \SpecialChar LyX
1587 , with established methods for handling
1588 unsupported styles and other changes.
1589 This way, no lyx2lyx code is required.
1592 \begin_layout Standard
1593 The steps to support a new version of an existing document class are thus:
1596 \begin_layout Itemize
1597 Create a new layout file including the upstream version in the name (avoid
1598 special characters like spaces and dots), e.g.
1600 \begin_inset Flex Code
1603 \begin_layout Plain Layout
1604 acmsiggraph-v0-92.layout
1612 \begin_layout Itemize
1613 Include the name of the
1614 \begin_inset Flex Code
1617 \begin_layout Plain Layout
1623 file as an optional argument in the
1624 \begin_inset Flex Code
1627 \begin_layout Plain Layout
1635 line and include the version number in the GUI name:
1636 \begin_inset Newline newline
1640 \begin_inset Flex Code
1643 \begin_layout Plain Layout
1646 DeclareLaTeXClass[acmsiggraph]{ACM SIGGGRAPH (v.
1647 \begin_inset space ~
1658 \begin_layout Itemize
1659 Update the GUI name in the old layout file (whose name should not be changed),
1661 \begin_inset Newline newline
1665 \begin_inset Flex Code
1668 \begin_layout Plain Layout
1671 DeclareLaTeXClass{ACM SIGGRAPH (<= v.
1672 \begin_inset space ~
1683 \begin_layout Itemize
1684 To avoid duplicate definitions, the new layout can
1685 \begin_inset Flex Code
1688 \begin_layout Plain Layout
1694 the old layout file and add\SpecialChar breakableslash
1695 remove\SpecialChar breakableslash
1696 obsolete\SpecialChar breakableslash
1697 modify settings and styles (similar
1699 \begin_inset Flex Code
1702 \begin_layout Plain Layout
1712 \begin_layout Standard
1713 It may be tempting to let the new layout be the
1714 \begin_inset Quotes eld
1718 \begin_inset Quotes erd
1721 and have the old layout import it.
1722 However, this should not be done because any changes to the new layout
1723 would need undo steps in the importing old layout.
1727 \begin_layout Itemize
1728 If the new LaTeX document class obsoletes the old one, update the example
1729 and template files to use the new layout.
1730 Add a note about the changes (preferably with a pointer to the documentation
1735 \begin_layout Standard
1736 This way, new documents based on the template or example will use the up-to-date
1737 document class version.
1741 \begin_layout Standard
1742 \begin_inset Newpage newpage
1748 \begin_layout Chapter
1752 \begin_layout Standard
1753 Automated tests are an important tool to detect bugs and regressions in
1754 software development.
1755 Some projects like gcc even require each bug fix to be accompanied by a
1756 test case for the automatic test suite, that would detect this bug.
1757 Testing interactive features automatically is of course very hard, but
1758 core functionality like document import and export can be tested quite
1759 easily, and some tests of this kind exist.
1762 \begin_layout Section
1766 \begin_layout Standard
1767 There are attempts to set up a suite of unit tests for LyX.
1770 \begin_layout Standard
1771 TODO: describe what is done and what is still to do.
1774 \begin_layout Section
1778 \begin_layout Standard
1779 The tex2lyx tests are located in the
1780 \begin_inset Flex Code
1783 \begin_layout Plain Layout
1789 subfolder of the \SpecialChar LyX
1790 source code distribution.
1791 The actual testing is performed by the simple python script
1792 \begin_inset Flex Code
1795 \begin_layout Plain Layout
1796 src/tex2lyx/test/runtests.py
1802 Each test consists of two files:
1803 \begin_inset Flex Code
1806 \begin_layout Plain Layout
1812 contains the \SpecialChar LaTeX
1813 code that should be tested.
1815 \begin_inset Flex Code
1818 \begin_layout Plain Layout
1824 contains the expected output of tex2lyx.
1825 When a test is run, the actual produced output is compared with the stored
1827 The test passes if both are identical.
1828 The test machinery is also able to generate a file
1829 \begin_inset Flex Code
1832 \begin_layout Plain Layout
1838 by exporting the produced .lyx file with \SpecialChar LyX
1840 This may be useful for roundtrip comparisons.
1843 \begin_layout Subsection
1847 \begin_layout Standard
1848 The tex2lyx tests can be run in several ways.
1850 \begin_inset Flex Code
1853 \begin_layout Plain Layout
1859 subfolder of the build directory, the commands
1860 \begin_inset Flex Code
1863 \begin_layout Plain Layout
1869 (cmake, all platforms),
1870 \begin_inset Flex Code
1873 \begin_layout Plain Layout
1879 (cmake, when using a make based build system and not MSVC) or
1880 \begin_inset Flex Code
1883 \begin_layout Plain Layout
1889 (autotools) will run the tex2lyx tests.
1890 Alternatively, in the root of the build directory, the command
1891 \begin_inset Flex Code
1894 \begin_layout Plain Layout
1900 runs all tests whose names match the regex
1901 \begin_inset Quotes eld
1905 \begin_inset Quotes erd
1909 Another way to run the tex2lyx tests in the root build directory is to
1910 instead use the command
1911 \begin_inset Flex Code
1914 \begin_layout Plain Layout
1915 ctest -L '(cmplyx|roundtrip)'
1920 , which runs all tests categorized with the label
1921 \begin_inset Quotes eld
1925 \begin_inset Quotes erd
1929 \begin_inset Quotes eld
1933 \begin_inset Quotes erd
1937 If a test fails, the differences between the expected and actual results
1938 are output in unified diff format.
1941 \begin_layout Subsection
1942 Updating test references
1943 \begin_inset CommandInset label
1945 name "sec:Updating-test-references"
1952 \begin_layout Standard
1953 In some cases a changed tex2lyx output is not a test failure, but wanted,
1955 \begin_inset space \thinspace{}
1959 \begin_inset space \space{}
1962 if a tex2lyx bug was fixed, or a new feature was added.
1963 In these cases the stored references need to be updated.
1964 To do so if using autotools, call
1965 \begin_inset Flex Code
1968 \begin_layout Plain Layout
1975 \begin_inset Flex Code
1978 \begin_layout Plain Layout
1984 subdirectory of the build directory.
1985 If instead using CMake, call
1986 \begin_inset Flex Code
1989 \begin_layout Plain Layout
1990 make updatetex2lyxtests
1995 in the build directory or in the
1996 \begin_inset Flex Code
1999 \begin_layout Plain Layout
2005 subdirectory of the build directory.
2009 \begin_layout Plain Layout
2010 Note that this is a case where a make target in the build directory can
2011 affect the source directory, which might not be advisable.
2016 On Windows do the following:
2019 \begin_layout Itemize
2020 Assure that the path to the python.exe is in your system PATH variable.
2023 \begin_layout Itemize
2024 Double-click on the file
2025 \begin_inset Flex Code
2028 \begin_layout Plain Layout
2029 updatetex2lyxtests.vcxproj
2034 in the build directory or in the
2035 \begin_inset Flex Code
2038 \begin_layout Plain Layout
2044 subdirectory of your build directory.
2047 \begin_layout Itemize
2048 In the appearing MSVC program assure that you build the
2052 version, then right-click on the project
2056 in the project explorer and choose then
2059 \begin_inset space ~
2062 Only\SpecialChar menuseparator
2064 \begin_inset space ~
2072 \begin_layout Standard
2073 For convenience, these commands also produce re-exported roundtrip .lyx.tex
2075 Please examine the changed output carefully before committing the changed
2076 files to the repository: Since the test machinery does not do a roundtrip
2078 \begin_inset Formula $\Rightarrow$
2082 \begin_inset Formula $\Rightarrow$
2085 .tex, and does not compare the produced dvi or pdf output, it assumes that
2086 the stored .lyx reference produces correct output if processed by \SpecialChar LyX
2088 There is only one chance to detect wrong output: before committing a new
2090 Once it is committed, it is quite difficult to verify whether it is correct.
2093 \begin_layout Standard
2098 update the test references by opening them with \SpecialChar LyX
2099 or directly running lyx2lyx
2101 This would not work, since lyx2lyx and \SpecialChar LyX
2102 produce slightly different files
2103 regarding insignificant whitespace and line breaks.
2106 \begin_layout Subsection
2110 \begin_layout Standard
2111 In many cases tests for new features may be added to one of the existing
2112 test files, but sometimes this is not possible or not wanted.
2113 Then a new test file needs to be added:
2116 \begin_layout Enumerate
2118 \begin_inset Flex Code
2121 \begin_layout Plain Layout
2122 src/tex2lyx/test/<test name>.tex
2127 and run tex2lyx in roundtrip mode to produce the file
2128 \begin_inset Flex Code
2131 \begin_layout Plain Layout
2132 src/tex2lyx/test/<test name>.lyx.lyx
2138 This file will be the new reference.
2141 \begin_layout Enumerate
2142 Once you confirmed that the tex2lyx output is correct, add the new files
2143 to the corresponding lists in
2144 \begin_inset Flex Code
2147 \begin_layout Plain Layout
2148 src/tex2lyx/test/runtests.py
2154 \begin_inset Flex Code
2157 \begin_layout Plain Layout
2158 src/tex2lyx/Makefile.am
2164 \begin_inset Flex Code
2167 \begin_layout Plain Layout
2168 src/tex2lyx/test/CMakeLists.txt
2176 \begin_layout Enumerate
2177 Commit the changes to the repository, or send a patch to the development
2178 list and ask for committing if you do not have commit rights.
2181 \begin_layout Section
2182 ctest automatic tests
2185 \begin_layout Standard
2186 Some tests are located in the
2187 \begin_inset Flex Code
2190 \begin_layout Plain Layout
2191 development/autotests/
2196 subfolder of the \SpecialChar LyX
2197 source code distribution.
2202 \begin_layout Plain Layout
2203 The README document in this folder only describes the
2204 \begin_inset Quotes eld
2208 \begin_inset Quotes erd
2211 subset of autotests!
2219 \begin_layout Standard
2220 These tests can be run by the commands
2221 \begin_inset Flex Code
2224 \begin_layout Plain Layout
2234 (all platforms) or (when using a make based build system and not MSVC)
2236 \begin_inset Flex Code
2239 \begin_layout Plain Layout
2246 \begin_inset Flex Code
2249 \begin_layout Plain Layout
2260 The test logs are written to the
2261 \begin_inset Flex Code
2264 \begin_layout Plain Layout
2278 \begin_layout Subsection
2282 \begin_layout Standard
2283 The export tests are integration tests.
2284 They take longer to run and are more likely to break than the tex2lyx tests.
2285 Nevertheless, they have caught many regressions and without a better alternativ
2286 e it is important to keep them up-to-date and understand how they work.
2289 \begin_layout Standard
2291 \begin_inset Quotes eld
2295 \begin_inset Quotes erd
2298 documentation, template, and example documents.
2299 In addition, there are a number of dedicated sample documents in the
2300 \begin_inset Flex Code
2303 \begin_layout Plain Layout
2309 subfolder of the \SpecialChar LyX
2310 source code distribution.
2311 All samples are (after copying and eventual processing by scripts) exported
2312 to various output formats via the
2313 \begin_inset Flex Code
2316 \begin_layout Plain Layout
2322 command line option.
2323 The tests checks for errors reported by LyX.
2324 (However, error-free export is no guarantee for an error-free output document.)
2327 \begin_layout Subsubsection
2328 \begin_inset CommandInset label
2330 name "par:when-to-run-an-export-test"
2334 Expectations of LyX developers
2337 \begin_layout Standard
2338 Because the export tests are integration tests and take a long time to run,
2339 LyX developers are rarely expected to run all of the tests.
2340 Here are some good practices to follow by developers:
2343 \begin_layout Itemize
2344 When making a non-trivial change to a .layout file, run the export and layout
2345 tests corresponding with that .layout file.
2348 \begin_layout Itemize
2349 When making non-trivial changes to a .lyx file, run the export tests correspondin
2350 g to that .lyx file.
2355 \begin_layout Plain Layout
2356 This rule is due to revision.
2360 \begin_layout Plain Layout
2361 There is an objection from the documentation maintainer that working on
2362 the documentation must not be complicated by having to consider non-standard
2366 \begin_layout Itemize
2367 successful compiling/testing an edited documentation file with pdflatex
2368 suffices to ensure it can be commited, not tests with other exports are
2372 \begin_layout Plain Layout
2373 If sudden failures with other exports due to “half-tested” documentation
2374 updates are a problem for the test maintainer, the test suite should use
2378 \begin_layout Itemize
2379 copied to a cache dir (autotests/samples/doc/, say) but not changed,
2382 \begin_layout Itemize
2383 updated regularely (but on a time chosen by the test suite maintainer) from
2384 the originals in lib/doc/
2387 \begin_layout Plain Layout
2391 \begin_layout Itemize
2392 no test will fail due to ongoing work on documentation,
2395 \begin_layout Itemize
2396 the documentation is still tested in full (with some delay),
2399 \begin_layout Itemize
2400 failures with non-default export can be examined and handled accordingly
2401 in one run with the cache update,
2404 \begin_layout Itemize
2405 “interesting failures” (like the nested-language+polyglossia problem in
2406 es/Customization can be separated and moved into dedicated test samples.
2414 \begin_layout Itemize
2415 When making non-trivial changes to LyX's \SpecialChar LaTeX
2417 touching the encoding code or package handling code that you expect will
2418 change the exported \SpecialChar LaTeX
2423 \begin_layout Standard
2424 \paragraph_spacing single
2425 Consider running all of the export tests before and after your change.
2426 If there are differences, please reconcile these (i.e.
2427 fix the bug or fix the tests)
2432 Ask for help if you're not sure what to.
2435 \begin_layout Standard
2436 If you do not want to run the tests,
2439 \begin_layout Itemize
2440 post the patch on the list and others will run the tests and eventually
2444 \begin_layout Itemize
2445 commit, but be prepared to fix eventually arising problems or to revert
2446 the commit if there is no easy fix.
2450 \begin_layout Itemize
2451 Understand how to interpret test failures.
2452 If your commit is found to have broken a test, you should be able to interpret
2453 the test results when made aware of them.
2455 \begin_inset CommandInset ref
2457 reference "subsec:Interpreting-export-tests"
2464 \begin_layout Subsubsection
2465 \begin_inset CommandInset label
2467 name "par:export-test-output-formats"
2474 \begin_layout Standard
2475 The following output formats are currently tested for each sample document
2477 \begin_inset CommandInset ref
2479 reference "par:Export-test-filtering"
2486 \begin_layout Labeling
2487 \labelwidthstring 00.00.0000
2492 \begin_layout Labeling
2493 \labelwidthstring 00.00.0000
2494 lyx16 LyX 1.6 file format (lyx2lyx)
2497 \begin_layout Labeling
2498 \labelwidthstring 00.00.0000
2499 lyx21 LyX 2.1 file format (lyx2lyx)
2502 \begin_layout Labeling
2503 \labelwidthstring 00.00.0000
2504 xhtml LyXHTML (native LyX HTML export)
2508 \begin_layout Labeling
2509 \labelwidthstring 00.00.0000
2511 \begin_inset space ~
2515 \begin_inset space ~
2522 \begin_layout Labeling
2523 \labelwidthstring pdf5msystemFM
2524 dvi DVI (8-bit latex)
2527 \begin_layout Labeling
2528 \labelwidthstring pdf5msystemFM
2529 dvi3_texF DVI (LuaTeX with 8-bit TeX fonts)
2532 \begin_layout Labeling
2533 \labelwidthstring pdf5msystemFM
2534 dvi3_systemF DVI (LuaTeX with Unicode fonts)
2537 \begin_layout Labeling
2538 \labelwidthstring pdf5msystemFM
2542 \begin_layout Labeling
2543 \labelwidthstring pdf5msystemFM
2544 pdf4_texF PDF (XeTeX with 8-bit TeX fonts)
2547 \begin_layout Labeling
2548 \labelwidthstring pdf5msystemFM
2549 pdf4_systemF PDF (XeTeX with Unicode fonts)
2552 \begin_layout Labeling
2553 \labelwidthstring pdf5msystemFM
2554 pdf5_texF PDF (LuaTeX with 8-bit TeX fonts)
2557 \begin_layout Labeling
2558 \labelwidthstring pdf5msystemFM
2559 pdf5_systemF PDF (LuaTeX with Unicode fonts)
2563 \begin_layout Labeling
2564 \labelwidthstring 00.00.0000
2566 \begin_inset space ~
2570 \begin_inset space ~
2574 \begin_inset space ~
2578 \begin_inset space ~
2585 \begin_layout Labeling
2586 \labelwidthstring pdf5msystemFM
2587 pdf DVI -> PS (dvips) -> PDF (ps2pdf)
2590 \begin_layout Labeling
2591 \labelwidthstring pdf5msystemFM
2592 pdf3 DVI -> PDF (dvipdfm)
2596 \begin_layout Labeling
2597 \labelwidthstring 00.00.0000
2599 \begin_inset space ~
2602 tested: (or only if set as default output format in the document source)
2606 \begin_layout Labeling
2607 \labelwidthstring pdf5msystemFM
2611 \begin_layout Labeling
2612 \labelwidthstring pdf5msystemFM
2613 luatex LaTeX (LuaTeX)
2616 \begin_layout Labeling
2617 \labelwidthstring pdf5msystemFM
2618 dviluatex LaTeX (dviluatex)
2621 \begin_layout Labeling
2622 \labelwidthstring pdf5msystemFM
2623 pdflatex LaTeX (pdflatex)
2626 \begin_layout Labeling
2627 \labelwidthstring pdf5msystemFM
2628 platex LaTeX (pLaTeX)
2631 \begin_layout Labeling
2632 \labelwidthstring pdf5msystemFM
2636 \begin_layout Labeling
2637 \labelwidthstring pdf5msystemFM
2638 eps3 EPS (encapsulated Postscript) (cropped)
2641 \begin_layout Labeling
2642 \labelwidthstring pdf5msystemFM
2643 ps DVI -> Postscript (dvips)
2646 \begin_layout Labeling
2647 \labelwidthstring pdf5msystemFM
2651 \begin_layout Labeling
2652 \labelwidthstring pdf5msystemFM
2653 text (nor text2, ..., text4)
2656 \begin_layout Labeling
2657 \labelwidthstring pdf5msystemFM
2661 \begin_layout Labeling
2662 \labelwidthstring pdf5msystemFM
2666 \begin_layout Labeling
2667 \labelwidthstring pdf5msystemFM
2671 \begin_layout Labeling
2672 \labelwidthstring pdf5msystemFM
2677 \begin_layout Subsubsection
2678 \begin_inset CommandInset label
2680 name "par:Configuring-ctests"
2684 Configuring the tests
2687 \begin_layout Standard
2688 To enable the export autotests, add the
2689 \begin_inset Flex Code
2692 \begin_layout Plain Layout
2693 -DLYX_ENABLE_EXPORT_TESTS=ON
2702 \begin_layout Standard
2703 \begin_inset Flex Code
2706 \begin_layout Plain Layout
2707 cmake -DLYX_ENABLE_EXPORT_TESTS=ON /path/to/source
2715 \begin_layout Standard
2717 This flag will increase the time for the cmake command by several seconds,
2718 mainly because of the process of inverting tests (see Section
2719 \begin_inset CommandInset ref
2721 reference "subsec:Interpreting-export-tests"
2728 \begin_layout Subsubsection
2729 \begin_inset CommandInset label
2731 name "par:ctest-options"
2738 \begin_layout Standard
2739 To run all tests, in the build directory simply run the command
2740 \begin_inset Flex Code
2743 \begin_layout Plain Layout
2750 A full, up-to-date TeXLive installation is recommended to run the tests.
2751 Otherwise, some tests will fail.
2752 Tests with additional requirements are labeled
2753 \begin_inset Quotes eld
2756 unreliable:nonstandard
2757 \begin_inset Quotes erd
2764 \begin_layout Standard
2765 To run only some of the tests, use command line options (see examples below):
2768 \begin_layout Labeling
2769 \labelwidthstring -R
2770 \begin_inset Flex Code
2773 \begin_layout Plain Layout
2779 Run only the tests whose names match the given regular expression.
2782 \begin_layout Labeling
2783 \labelwidthstring -R
2784 \begin_inset Flex Code
2787 \begin_layout Plain Layout
2793 Run only the tests whose labels match the given regular expression.
2794 A test may have more that one label.
2798 \begin_layout Labeling
2799 \labelwidthstring -R
2800 \begin_inset Flex Code
2803 \begin_layout Plain Layout
2809 Exclude the tests whose names match the given regular expression.
2812 \begin_layout Labeling
2813 \labelwidthstring -R
2814 \begin_inset Flex Code
2817 \begin_layout Plain Layout
2823 Exclude the tests whose labels match the given regular expression.
2824 Cannot be combined with
2825 \begin_inset Flex Code
2828 \begin_layout Plain Layout
2837 \begin_layout Standard
2838 The following options help to find good selection patterns:
2841 \begin_layout Labeling
2842 \labelwidthstring -R
2843 \begin_inset Flex Code
2846 \begin_layout Plain Layout
2852 List the tests that would be run but not actually run them.
2857 \begin_layout Standard
2858 Useful in conjunction with the -R, -L, -E and -LE options, e.g., if you want
2859 to know how many tests there are or whether your
2860 \begin_inset Flex Code
2863 \begin_layout Plain Layout
2869 regular expression did what you expected.
2873 \begin_layout Labeling
2874 \labelwidthstring -R
2875 \begin_inset Flex Code
2878 \begin_layout Plain Layout
2879 \SpecialChar nobreakdash
2880 \SpecialChar nobreakdash
2886 print the list of all labels associated with the test set.
2887 Can also be combined with -R, -L, -E, ...
2891 \begin_layout Standard
2892 Other useful options are:
2895 \begin_layout Labeling
2896 \labelwidthstring -R
2897 \begin_inset Flex Code
2900 \begin_layout Plain Layout
2906 Run the tests in parallel using the given number of jobs.
2910 \begin_layout Standard
2911 We are still working on getting the tests to run in parallel.
2912 However, when running the tests in parallel, sometimes tests fail that
2913 pass when run sequentially.
2914 A reasonable approach is to first run the tests in parallel and then run
2915 the failed tests sequentially.
2918 \begin_layout Standard
2919 For example, to run 8 jobs at a time:
2922 \begin_layout Standard
2923 \begin_inset Flex Code
2926 \begin_layout Plain Layout
2935 \begin_layout Standard
2936 \begin_inset Flex Code
2939 \begin_layout Plain Layout
2940 ctest \SpecialChar nobreakdash
2941 \SpecialChar nobreakdash
2950 \begin_layout Standard
2951 When specifying a subset of the tests (e.g.
2953 \begin_inset Flex Code
2956 \begin_layout Plain Layout
2957 \SpecialChar nobreakdash
2963 ), the same subset must be specified when using the
2964 \begin_inset Flex Code
2967 \begin_layout Plain Layout
2968 \SpecialChar nobreakdash
2969 \SpecialChar nobreakdash
2975 option because it is the test numbers that are used to index which tests
2976 failed on the previous run.
2979 \begin_layout Standard
2981 Note that some tests cannot be run in parallel.
2982 These tests are marked in the code with the
2983 \begin_inset Flex Code
2986 \begin_layout Plain Layout
2996 \begin_layout Labeling
2997 \labelwidthstring -R
2998 \begin_inset Flex Code
3001 \begin_layout Plain Layout
3002 \SpecialChar nobreakdash
3003 \SpecialChar nobreakdash
3009 Set a global timeout on all tests that do not already have a timeout set
3014 \begin_layout Standard
3015 There have been bugs in LyX and in \SpecialChar LaTeX
3016 which cause compilation to hang, and
3017 without a timeout a test might never stop (in one case there was even a
3019 If a test times out, the
3020 \begin_inset Flex Code
3023 \begin_layout Plain Layout
3029 command exits with error, but you can distinguish between a timed out test
3030 and a failed test in the output reported at the end of the
3031 \begin_inset Flex Code
3034 \begin_layout Plain Layout
3044 \begin_layout Standard
3046 \begin_inset Flex Code
3049 \begin_layout Plain Layout
3055 ) the full list of command line options.
3058 \begin_layout Subsubsection
3062 \begin_layout Itemize
3063 run only the export tests:
3064 \begin_inset Flex Code
3067 \begin_layout Plain Layout
3076 \begin_layout Itemize
3078 \begin_inset Flex Code
3081 \begin_layout Plain Layout
3082 ctest -L "inverted|suspended"
3090 \begin_layout Itemize
3091 list all export tests which match any of the labelling patterns:
3092 \begin_inset Flex Code
3095 \begin_layout Plain Layout
3106 \begin_layout Itemize
3107 exclude rarely used output formats and post-processing tests
3108 \begin_inset Flex Code
3111 \begin_layout Plain Layout
3112 ctest -L export -E "_(texF|dvi3|pdf3?)"
3120 \begin_layout Subsubsection
3121 \begin_inset CommandInset label
3123 name "subsec:Interpreting-export-tests"
3127 Interpreting the export test results
3130 \begin_layout Standard
3131 A test can fail for several reasons, not all of them bad.
3134 \begin_layout Enumerate
3135 A new or edited sample document may be incompatible with some output formats.
3138 \begin_layout Enumerate
3139 A dependency is not met (e.g.
3140 the \SpecialChar LaTeX
3142 One hint that this is the case is that the corresponding
3143 \begin_inset Flex Code
3146 \begin_layout Plain Layout
3152 test will likely also fail.
3155 \begin_layout Enumerate
3156 An inverted test fails to fail (i.e.
3157 export that previously failed now works).
3160 \begin_layout Enumerate
3161 An external dependency was updated (e.g.
3166 \begin_layout Enumerate
3167 A recent code change introduced a bug.
3170 \begin_layout Enumerate
3171 \begin_inset CommandInset label
3177 A change in a document exposed a previously unknown bug or an incompatibility
3178 with an export format (e.g.
3179 Lua\SpecialChar LaTeX
3183 \begin_layout Standard
3184 Because the .lyx files are exported in several formats, it is not surprising
3185 that many of the exports fail.
3186 This expectation of failure is addressed by
3187 \begin_inset Quotes eld
3191 \begin_inset Quotes erd
3194 the tests, that is, by marking the test as
3195 \begin_inset Quotes eld
3199 \begin_inset Quotes erd
3202 if the export exits with error and as
3203 \begin_inset Quotes eld
3207 \begin_inset Quotes erd
3210 if the export succeeds
3215 It follows that these expected failures will not show up as failed tests
3216 in the test results and thus will not pollute the
3217 \begin_inset Quotes eld
3221 \begin_inset Quotes erd
3225 If the export actually succeeds, then the test will fail.
3226 The purpose of this failure is to get your attention—something has changed,
3227 possibly for the better.
3230 \begin_layout Standard
3231 We try to document why a test is inverted or ignored.
3232 See the comment (prefixed with
3233 \begin_inset Flex Code
3236 \begin_layout Plain Layout
3242 ) above the block in which the test is listed as inverted or ignored in
3244 \begin_inset Flex Code
3247 \begin_layout Plain Layout
3248 development/autotests/invertedTests
3254 \begin_inset Flex Code
3257 \begin_layout Plain Layout
3258 development/autotests/unreliableTests
3264 \begin_inset Flex Code
3267 \begin_layout Plain Layout
3268 development/autotests/ignoredTests
3277 \begin_layout Standard
3278 A good question is why do we enable the tests for non-default formats? The
3279 answer is that if a non-default route is broken it is often because a bug
3280 was introduced in LyX and not because a document-specific change was made
3281 that is not supported by the route.
3282 In other words, there is a high signal/noise ratio in the export tests
3283 for some non-default formats.
3287 \begin_layout Standard
3288 When a test or several tests fail, consider checking the files in the
3289 \begin_inset Flex Code
3292 \begin_layout Plain Layout
3298 subdirectory of your build directory.
3299 In this subdirectory are three files: the file
3300 \begin_inset Flex Code
3303 \begin_layout Plain Layout
3309 simply lists the tests that failed on your last
3310 \begin_inset Flex Code
3313 \begin_layout Plain Layout
3320 \begin_inset Flex Code
3323 \begin_layout Plain Layout
3329 file contains the output from the tests (and often has details explaining
3330 why a test failed); and the
3331 \begin_inset Flex Code
3334 \begin_layout Plain Layout
3340 file lists the times that it took to run the tests.
3343 \begin_layout Subsubsection
3344 What action should you take if a test fails?
3347 \begin_layout Standard
3348 \paragraph_spacing single
3349 It is always good to check manually why something fails and if it passes
3350 if the PDF output is good.
3353 \begin_layout Itemize
3354 Generally, if a change breaks compilation for the target format (for the
3355 manuals pdf2) without solving some important other issue,
3357 fix or revert the commit
3359 that led to failure.
3362 \begin_layout Itemize
3363 If it is not possible to (immediately) fix the failure but there are reasons
3364 not to revert the commit (e.g.
3365 it fixes another more important issue),
3369 the failing test case (see
3370 \begin_inset CommandInset ref
3372 reference "par:Inverted-tests"
3379 \begin_layout Itemize
3384 test case fails because the export now works, first confirm that the output
3385 of the corresponding export looks good (e.g., not garbled text).
3390 the test by removing the pattern from the
3391 \begin_inset Quotes eld
3395 \begin_inset Quotes erd
3399 \begin_inset CommandInset ref
3401 reference "par:Inverted-tests"
3408 \begin_layout Itemize
3409 If the export did not fail previously but led to wrong output (PDF, say),
3413 \begin_layout Plain Layout
3414 Non-failing test with wrong output should be labeled as
3415 \begin_inset Quotes eld
3418 unreliable:wrong_output
3419 \begin_inset Quotes erd
3423 \begin_inset CommandInset ref
3425 reference "par:Unreliable-tests"
3434 it is in fact an improvement when the test now fails.
3439 the failing test case (see
3440 \begin_inset CommandInset ref
3442 reference "par:Inverted-tests"
3449 \begin_layout Itemize
3450 In case of tests failing due to missing requirements (tests labeled
3451 \begin_inset Quotes eld
3454 unreliable:nonstandard
3455 \begin_inset Quotes erd
3458 or testing on a system with only a subset of TeXLive installed), ignore
3459 the failure, ask for someone else to run the test, or install the missing
3460 resources and try again.
3463 \begin_layout Itemize
3464 Check the log file Testing/Temporary/LastTest.log.
3465 In case of latex-errors rerun the failing test with environment variable
3466 'LYX_DEBUG_LATEX' set to '1'.
3467 This will include latex messages in LastTest.log, so it should be easier
3468 to interpret the fail-reason.
3471 \begin_layout Subsubsection
3472 \begin_inset CommandInset label
3474 name "par:Inverted-tests"
3481 \begin_layout Standard
3482 Test cases whose name matches a pattern in the file
3483 \begin_inset Flex Code
3486 \begin_layout Plain Layout
3487 development/autotests/invertedTests
3497 They get also the test property
3498 \begin_inset Flex Code
3501 \begin_layout Plain Layout
3508 they are reported as failing if the export works without error
3509 \begin_inset Flex URL
3512 \begin_layout Plain Layout
3514 https://cmake.org/cmake/help/v3.0/command/set_tests_properties.html
3522 \begin_layout Standard
3523 Add failing cases to this file, if they cannot be solved
3524 \begin_inset Quotes eld
3528 \begin_inset Quotes erd
3531 but it is expected that the export will work in a foreseeable future, e.g.
3532 low priority issues like failures to export to a non-target format (for
3533 the manuals everything except pdf2).
3536 \begin_layout Standard
3537 The following sublabels are currently present in
3538 \begin_inset Flex Code
3541 \begin_layout Plain Layout
3550 \begin_layout Description
3551 todo test failures that require attention:
3555 \begin_layout Itemize
3556 minor issues to explore and properly sort later,
3559 \begin_layout Itemize
3563 \begin_layout Itemize
3564 LyX bugs to report at trac (move pattern to section "lyxbugs" once done).
3568 \begin_layout Description
3569 lyxbugs LyX bugs with a Trac number.
3572 \begin_layout Description
3573 ert Export failures due to "raw" LaTeX use in ERT or preamble code.
3577 \begin_layout Standard
3578 "Wontfix" if demonstrating correct use and OK in the default output format.
3582 \begin_layout Description
3583 texissues Export fails due to LaTeX limitations like non-ASCII characters
3584 in verbatim or listings, incompatible packages, ...
3588 \begin_layout Standard
3589 "Wontfix" if documents demonstrate correct use in the default output format:
3592 \begin_layout Itemize
3593 If the source can be made more robust without becoming "hackish", fix the
3597 \begin_layout Itemize
3598 if LyX could be enhanced to care for a permanent TeX limitation, file a
3599 ticket at trac and add a pattern under lyxbugs,
3602 \begin_layout Itemize
3603 otherwise, add a pattern here.
3607 \begin_layout Description
3608 attic Documents in the attic (kept for reference and format conversion test).
3610 \begin_inset Quotes eld
3614 \begin_inset Quotes erd
3620 \begin_layout Paragraph
3624 \begin_layout Standard
3625 Test cases whose name additionally matches a pattern in the file
3626 \begin_inset Flex Code
3629 \begin_layout Plain Layout
3630 development/autotests/suspendedTests
3648 This means they are not executed using
3649 \begin_inset Flex Code
3652 \begin_layout Plain Layout
3659 \begin_inset Flex Code
3662 \begin_layout Plain Layout
3669 However, they also get the test property
3670 \begin_inset Flex Code
3673 \begin_layout Plain Layout
3680 they are reported as failing if the export works without error.
3681 From time to time they still have to be checked using
3682 \begin_inset Flex Code
3685 \begin_layout Plain Layout
3694 \begin_layout Standard
3695 These tests are suspended, because the export fails for known reasons which
3696 cannot ATM be resolved.
3697 But it is expected the reason might disappear in the future.
3698 Be it new TL or better handling in \SpecialChar LyX
3702 \begin_layout Standard
3703 For ctest commands without the
3704 \begin_inset Flex Code
3707 \begin_layout Plain Layout
3713 parameter nothing changes.
3714 Suspended or not, tests will be executed depending only on the selecting
3715 regular expression given to the ctest command (see
3716 \begin_inset CommandInset ref
3718 reference "par:ctest-options"
3725 \begin_layout Subsubsection
3726 \begin_inset CommandInset label
3728 name "par:Unreliable-tests"
3735 \begin_layout Standard
3736 Test cases whose name matches a pattern in the file
3737 \begin_inset Flex Code
3740 \begin_layout Plain Layout
3741 development/autotests/unreliableTests
3753 \begin_layout Standard
3754 These tests are not executed using
3755 \begin_inset Flex Code
3758 \begin_layout Plain Layout
3765 \begin_inset Flex Code
3768 \begin_layout Plain Layout
3778 \begin_layout Standard
3779 They pass or fail for various reasons not related to LyX (nonstandard, erratic)
3780 or pass but should rather fail (wrong output).
3782 \begin_inset Note Note
3785 \begin_layout Plain Layout
3786 *invalid* tests (wrong output) are not *unreliable*.
3787 # Use "unfit" or "unapplicable" as better label and name of pattern file?
3796 \begin_layout Standard
3797 The following sublabels are currently present in
3798 \begin_inset Flex Code
3801 \begin_layout Plain Layout
3810 \begin_layout Description
3811 nonstandard Documents with additional requirements, e.g.
3812 a class or package file not in TeXLive.
3814 \begin_inset Note Note
3817 \begin_layout Plain Layout
3819 \begin_inset Quotes eld
3823 \begin_inset Quotes erd
3827 \begin_inset Quotes eld
3831 \begin_inset Quotes erd
3842 \begin_layout Description
3843 erratic Tests depending on local configuration or the phase of the moon.
3847 \begin_layout Description
3848 varying_versions Tests depending on e.g.
3849 OS or version of a non-TeX-Live dependency.
3850 Note that a full, up-to-date TeX Live installation is required so this
3851 sublabel is about versions of other dependencies.
3854 \begin_layout Description
3856 \begin_inset space ~
3859 output Export does not fail but the resulting document has (undetected)
3864 \begin_layout Standard
3865 \paragraph_spacing single
3866 \begin_inset Note Note
3869 \begin_layout Plain Layout
3870 \paragraph_spacing single
3871 These tests are in a strict sense not unreliable but
3875 (not measuring what they should measure).
3884 \begin_layout Subsubsection
3885 \begin_inset CommandInset label
3887 name "par:Export-test-filtering"
3891 Export test filtering
3894 \begin_layout Standard
3895 The assignment of a label to a test is controlled by a set of files with
3896 regular expressions that are matched against the test names.
3899 \begin_layout Description
3900 ignoredTests (small file)
3901 \begin_inset Newline newline
3904 Tests selected here are withdrawn in the configuration step (cf.
3906 \begin_inset CommandInset ref
3908 reference "par:Configuring-ctests"
3916 \begin_layout Labeling
3917 \labelwidthstring 00.00.0000
3918 Input Test of any export combination
3921 \begin_layout Labeling
3922 \labelwidthstring 00.00.0000
3923 Output Stop if tests not selected here
3927 \begin_layout Description
3928 unreliableTests: Tests selected pass or fail dependent on the system where
3930 Selected tests gain the label 'unreliable'.
3934 \begin_layout Labeling
3935 \labelwidthstring 00.00.0000
3936 Input Each test which passed 'ignoredTests'
3939 \begin_layout Labeling
3940 \labelwidthstring 00.00.0000
3941 Output Gain label 'unreliable', proceed with checking for 'inverted'.
3945 \begin_layout Description
3947 \begin_inset space \space{}
3954 \begin_layout Labeling
3955 \labelwidthstring 00.00.0000
3956 Input Each test which passed 'ignoredTests'
3959 \begin_layout Labeling
3960 \labelwidthstring 00.00.0000
3961 Output Stop if not selected, gain test-property 'WILL_FAIL' (i.e.
3962 tests are reported as failing if the export works without error.) If no
3963 subselection applies, gain labels 'export' and 'inverted'.
3966 \begin_layout Standard
3967 The following filter perfoms a subselection of 'invertedTests':
3970 \begin_layout Description
3971 suspendedTests Tests selected here gain the label 'suspended' but _not_
3972 'export' or 'inverted', although in ctest they remain inverted.
3973 ('ctest' knows only 'inverted' or not, labels are used only for test selection)
3977 \begin_layout Labeling
3978 \labelwidthstring 00.00.0000
3979 Input Each test selected by 'invertedTests'
3982 \begin_layout Labeling
3983 \labelwidthstring 00.00.0000
3984 Output Selected test gains label 'suspended'.
3990 \begin_layout Standard
3991 The following table may clarify label assignement
3994 \begin_layout Standard
3995 \begin_inset space \hspace{}
4000 \begin_inset Tabular
4001 <lyxtabular version="3" rows="6" columns="8">
4002 <features tabularvalignment="middle">
4003 <column alignment="left" valignment="top" width="2cm">
4004 <column alignment="left" valignment="top" width="2.5cm">
4005 <column alignment="left" valignment="top" width="2cm">
4006 <column alignment="center" valignment="top" width="2.5cm">
4007 <column alignment="center" valignment="top">
4008 <column alignment="center" valignment="top">
4009 <column alignment="center" valignment="top">
4010 <column alignment="center" valignment="top">
4012 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4015 \begin_layout Plain Layout
4016 Test matching pattern in file:
4021 <cell multicolumn="2" alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4024 \begin_layout Plain Layout
4030 <cell multicolumn="2" alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4033 \begin_layout Plain Layout
4039 <cell multicolumn="2" alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4042 \begin_layout Plain Layout
4048 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4051 \begin_layout Plain Layout
4057 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4060 \begin_layout Plain Layout
4066 <cell multicolumn="2" alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4069 \begin_layout Plain Layout
4075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4078 \begin_layout Plain Layout
4086 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4089 \begin_layout Plain Layout
4090 ignored\SpecialChar softhyphen
4096 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4099 \begin_layout Plain Layout
4100 unreliable\SpecialChar softhyphen
4106 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4109 \begin_layout Plain Layout
4110 inverted\SpecialChar softhyphen
4116 <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4119 \begin_layout Plain Layout
4120 suspended\SpecialChar softhyphen
4126 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4129 \begin_layout Plain Layout
4135 <cell alignment="center" valignment="top" topline="true" usebox="none">
4138 \begin_layout Plain Layout
4144 <cell alignment="center" valignment="top" topline="true" usebox="none">
4147 \begin_layout Plain Layout
4153 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4156 \begin_layout Plain Layout
4164 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4167 \begin_layout Plain Layout
4173 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4176 \begin_layout Plain Layout
4182 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4185 \begin_layout Plain Layout
4191 <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4194 \begin_layout Plain Layout
4200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4203 \begin_layout Plain Layout
4209 <cell alignment="center" valignment="top" topline="true" usebox="none">
4212 \begin_layout Plain Layout
4218 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4221 \begin_layout Plain Layout
4227 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4230 \begin_layout Plain Layout
4238 <cell multirow="3" alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4241 \begin_layout Plain Layout
4247 <cell multirow="3" alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4250 \begin_layout Plain Layout
4252 \begin_inset Newline newline
4256 \begin_inset Newline newline
4264 <cell multirow="3" alignment="left" valignment="middle" topline="true" bottomline="true" leftline="true" usebox="none">
4267 \begin_layout Plain Layout
4273 <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4276 \begin_layout Plain Layout
4282 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4285 \begin_layout Plain Layout
4291 <cell alignment="center" valignment="top" topline="true" usebox="none">
4294 \begin_layout Plain Layout
4300 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4303 \begin_layout Plain Layout
4309 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4312 \begin_layout Plain Layout
4320 <cell multirow="4" alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4323 \begin_layout Plain Layout
4329 <cell multirow="4" alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4332 \begin_layout Plain Layout
4338 <cell multirow="4" alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4341 \begin_layout Plain Layout
4347 <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4350 \begin_layout Plain Layout
4356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4359 \begin_layout Plain Layout
4365 <cell alignment="center" valignment="top" topline="true" usebox="none">
4368 \begin_layout Plain Layout
4374 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4377 \begin_layout Plain Layout
4383 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4386 \begin_layout Plain Layout
4394 <cell multirow="4" alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4397 \begin_layout Plain Layout
4403 <cell multirow="4" alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4406 \begin_layout Plain Layout
4412 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4415 \begin_layout Plain Layout
4421 <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4424 \begin_layout Plain Layout
4430 <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4433 \begin_layout Plain Layout
4439 <cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
4442 \begin_layout Plain Layout
4448 <cell alignment="center" valignment="top" topline="true" bottomline="true" rightline="true" usebox="none">
4451 \begin_layout Plain Layout
4457 <cell alignment="center" valignment="top" topline="true" bottomline="true" rightline="true" usebox="none">
4460 \begin_layout Plain Layout
4474 \begin_layout Standard
4475 \begin_inset Note Note
4478 \begin_layout Plain Layout
4480 \begin_inset Quotes eld
4484 \begin_inset Quotes erd
4487 filter, this would be far less complicated:
4490 \begin_layout Plain Layout
4491 \begin_inset Tabular
4492 <lyxtabular version="3" rows="6" columns="7">
4493 <features tabularvalignment="middle">
4494 <column alignment="left" valignment="top" width="0pt">
4495 <column alignment="left" valignment="top" width="0pt">
4496 <column alignment="left" valignment="top" width="0pt">
4497 <column alignment="center" valignment="top">
4498 <column alignment="center" valignment="top">
4499 <column alignment="center" valignment="top">
4500 <column alignment="center" valignment="top">
4502 <cell multicolumn="1" alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4505 \begin_layout Plain Layout
4506 Test matching pattern in file:
4511 <cell multicolumn="2" alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4514 \begin_layout Plain Layout
4520 <cell multicolumn="2" alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
4523 \begin_layout Plain Layout
4529 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4532 \begin_layout Plain Layout
4538 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4541 \begin_layout Plain Layout
4547 <cell multicolumn="2" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4550 \begin_layout Plain Layout
4556 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4559 \begin_layout Plain Layout
4567 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4570 \begin_layout Plain Layout
4576 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4579 \begin_layout Plain Layout
4585 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4588 \begin_layout Plain Layout
4594 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4597 \begin_layout Plain Layout
4603 <cell alignment="center" valignment="top" topline="true" usebox="none">
4606 \begin_layout Plain Layout
4612 <cell alignment="center" valignment="top" topline="true" usebox="none">
4615 \begin_layout Plain Layout
4621 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4624 \begin_layout Plain Layout
4632 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4635 \begin_layout Plain Layout
4641 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4644 \begin_layout Plain Layout
4650 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4653 \begin_layout Plain Layout
4659 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4662 \begin_layout Plain Layout
4668 <cell alignment="center" valignment="top" topline="true" usebox="none">
4671 \begin_layout Plain Layout
4677 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4680 \begin_layout Plain Layout
4686 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4689 \begin_layout Plain Layout
4697 <cell multirow="3" alignment="left" valignment="middle" topline="true" bottomline="true" leftline="true" usebox="none">
4700 \begin_layout Plain Layout
4706 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4709 \begin_layout Plain Layout
4715 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4718 \begin_layout Plain Layout
4724 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4727 \begin_layout Plain Layout
4733 <cell alignment="center" valignment="top" topline="true" usebox="none">
4736 \begin_layout Plain Layout
4742 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4745 \begin_layout Plain Layout
4751 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4754 \begin_layout Plain Layout
4762 <cell multirow="4" alignment="left" valignment="middle" topline="true" leftline="true" usebox="none">
4765 \begin_layout Plain Layout
4771 <cell multirow="3" alignment="left" valignment="middle" topline="true" bottomline="true" leftline="true" usebox="none">
4774 \begin_layout Plain Layout
4780 <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4783 \begin_layout Plain Layout
4789 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4792 \begin_layout Plain Layout
4798 <cell alignment="center" valignment="top" topline="true" usebox="none">
4801 \begin_layout Plain Layout
4807 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4810 \begin_layout Plain Layout
4816 <cell alignment="center" valignment="top" topline="true" rightline="true" usebox="none">
4819 \begin_layout Plain Layout
4827 <cell multirow="4" alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4830 \begin_layout Plain Layout
4836 <cell multirow="4" alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4839 \begin_layout Plain Layout
4845 <cell alignment="left" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4848 \begin_layout Plain Layout
4854 <cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
4857 \begin_layout Plain Layout
4863 <cell alignment="center" valignment="top" topline="true" bottomline="true" usebox="none">
4866 \begin_layout Plain Layout
4872 <cell alignment="center" valignment="top" topline="true" bottomline="true" rightline="true" usebox="none">
4875 \begin_layout Plain Layout
4881 <cell alignment="center" valignment="top" topline="true" bottomline="true" rightline="true" usebox="none">
4884 \begin_layout Plain Layout
4903 \begin_layout Subsection
4907 \begin_layout Standard
4908 These tests check whether a .lyx file loads without any terminal messages.
4909 They correspond to the manual operations of simply opening a .lyx file on
4910 the terminal, exiting LyX once the file is loaded, and then checking whether
4911 there is any output from the terminal.
4912 These tests are useful for catching malformed .lyx files and parsing bugs.
4913 They can also be used to find a .lyx file in which an instance of something
4915 To do this, compile LyX with a local patch that outputs something to the
4916 terminal when an instance is found, and then run the check_load tests to
4917 see if any fail, which would mean that the situation occurs in the LyX
4918 documentation files corresponding to the failed tests.
4919 These tests are expectedly fragile: any LyX diagnostic message, which is
4920 not necessarily an error, would cause the tests to fail.
4921 Similarly, any message output by a library (e.g.
4922 Qt) would also cause failure.
4923 There are some messages that the check_load tests are instructed to ignore,
4924 which are stored in the file
4925 \begin_inset Flex Code
4928 \begin_layout Plain Layout
4929 development/autotests/filterCheckWarnings
4937 \begin_layout Standard
4938 Under cmake, the tests are labeled as 'load'.
4941 \begin_layout Subsection
4945 \begin_layout Standard
4946 Automated tests based on the "MonKey Testing" keytest program are enabled
4947 if the necessary dependencies are found and if the CMake flag
4948 \begin_inset Flex Code
4951 \begin_layout Plain Layout
4952 -DLYX_ENABLE_KEYTESTS=ON
4958 They are documented in the README document in
4959 \begin_inset Flex Code
4962 \begin_layout Plain Layout
4963 development/autotests
4968 subfolder of the \SpecialChar LyX
4969 source code distribution.
4972 \begin_layout Subsection
4976 \begin_layout Standard
4977 These tests combine lyx2lyx tests with check_load tests.
4978 They fail if either fails.
4981 \begin_layout Subsection
4985 \begin_layout Standard
4986 The URL tests are enabled with the
4987 \begin_inset Flex Code
4990 \begin_layout Plain Layout
4991 -DLYX_ENABLE_URLTESTS=ON
4996 CMake flag and are useful for finding broken links in our documentation
4998 If a URL test fails, to see which link in particular was reported as broken,
5000 \begin_inset Flex Code
5003 \begin_layout Plain Layout
5010 These tests are extremely fragile (e.g.
5011 a test can depend on your Internet connection) and a failed URL test should
5012 not be taken too seriously.
5013 URL tests are labeled as
5018 \begin_layout Subsubsection
5022 \begin_layout Standard
5023 cmake is required to run the \SpecialChar LyX
5024 tests, running them is not implemented for
5028 \begin_layout Standard
5029 The appropriate commands are:
5032 \begin_layout Itemize
5038 \begin_inset Newline newline
5041 runs all tests with label
5046 \begin_layout Itemize
5049 ctest -R 'check_.*urls'
5052 \begin_inset Newline newline
5055 runs the tests 'check_accessible_urls'
5058 \begin_layout Standard
5059 Associated test results can be examined in ctest-log directory in files
5060 of the form 'LastFailed.*URLS.log'
5063 \begin_layout Chapter
5064 Development policies
5067 \begin_layout Standard
5068 This chapter lists some guidelines that should be followed.
5069 This list is not complete, and many guidelines are in separate chapters,
5071 \begin_inset Quotes eld
5074 When is an update of the .lyx file format number needed?
5075 \begin_inset Quotes erd
5079 \begin_inset CommandInset ref
5081 reference "sec:When-is-an"
5088 \begin_layout Section
5089 When to set a fixed milestone?
5092 \begin_layout Standard
5093 Only set a fixed milestone (like 2.1.4 or 2.2.0) if at least one of the following
5097 \begin_layout Enumerate
5098 Somebody is actively working on a fix.
5101 \begin_layout Enumerate
5102 The bug is so severe that it would block the release if it is not fixed.
5105 \begin_layout Standard
5106 If a bug is important, but nobody is working on it, and it is no showstopper,
5107 use a milestone like 2.1.x or 2.2.x.
5108 For all other bugs, do not set a milestone at all.
5111 \begin_layout Section
5112 Can we add rc entries in stable branch?
5115 \begin_layout Standard
5117 We are supposed to increase the prefs2prefs version number with such things.
5120 \begin_layout Chapter
5121 \begin_inset CommandInset label
5123 name "sec:Documentation-policies"
5127 Documentation policies
5130 \begin_layout Section
5134 \begin_layout Standard
5136 \begin_inset space ~
5139 rules in editing the docs:
5142 \begin_layout Enumerate
5143 \begin_inset CommandInset label
5145 name "enu:If-you-are"
5149 If you are not the maintainer of a doc file or a chapter/section, you MUST
5150 use change tracking so that the maintainer could review your changes
5153 \begin_layout Enumerate
5154 Respect the formatting of the document.
5155 The different files use different formatting styles.
5156 That is OK and has historic reasons nobody fully knows ;-).
5157 But it is important to be consistent within one file.
5160 \begin_layout Enumerate
5161 All changes you make to a file in one language MUST also go the file in
5162 the other actively maintained languages.
5163 Normally the maintainer does this for you, if you are the maintainer, you
5164 must do this by copying or changing the changed or added text to the other
5165 files so that the translators sees the blue underlined text and know what
5166 they have to translate and what was changed.
5169 \begin_layout Enumerate
5170 You MUST assure that the document is compilable as
5171 \begin_inset Quotes eld
5175 \begin_inset Quotes erd
5178 or the document's default output format after your changes.
5181 \begin_layout Enumerate
5182 All fixes (typos, compilation fixes, updates info etc.) go at first into
5183 the current GIT branch because the user should benefit from all fixes with
5184 every minor release.
5185 Feel free to commit directly to branch as long as you follow rule
5186 \begin_inset space ~
5190 \begin_inset CommandInset ref
5192 reference "enu:If-you-are"
5197 You can immediately commit to master as well.
5200 \begin_layout Enumerate
5201 \begin_inset CommandInset label
5203 name "enu:The-fileformat-of"
5207 The fileformat of a file must not be changed unless you document a new feature
5208 in LyX that requires a new fileformat.
5209 The reason for this rule is to keep it easy for the doc maintainers to
5210 port/backport changes to from master/branch.
5213 \begin_layout Standard
5214 The main documentation consists of these files:
5217 \begin_layout Description
5218 Welcome.lyx it is the first file you see after an installation.
5219 We assume that a new user sees this.
5220 It is therefore designed to be as simple as possible.
5221 Therefore please don't add any new formatting, only fix typos etc.
5222 Welcome.lyx is up to date for \SpecialChar LyX
5223 2.1.x, currently maintained by Uwe Stöhr.
5226 \begin_layout Description
5227 Intro.lyx This is the manual new users will read to learn \SpecialChar LyX
5229 It therefore uses a limited set of formatting.
5230 For example a standard document class.
5231 Since new users will first learn about the formatting possibilities of
5233 please keep this file that simple.
5234 Intro.lyx is up to date for \SpecialChar LyX
5235 2.1.x, currently maintained by Uwe Stöhr.
5238 \begin_layout Description
5239 Tutorial.lyx our tutorial.
5240 It must be always up to date.
5241 Normally there is nothing to add since we don't want to overwhelm new users
5242 with too much details.
5243 The will learn these details while using \SpecialChar LyX
5244 and we have special manuals.
5245 Tutorial.lyx is up to date for \SpecialChar LyX
5246 2.1.x, currently maintained by Uwe Stöhr.
5249 \begin_layout Description
5250 UserGuide.lyx our main user guide.
5251 It covers a mixture of basic and detailed information.
5252 Some information is also in the Math and EmbeddedObjects manual so that
5253 the UserGuide refers to these files.
5254 UserGuide.lyx is up to date for \SpecialChar LyX
5255 2.1.x, currently maintained by Uwe Stöhr.
5258 \begin_layout Description
5259 EmbeddedObjects.lyx a special manual to explain things like tables floats
5262 EmbeddedObjects.lyx is up to date for \SpecialChar LyX
5263 2.1.x, currently maintained by Uwe
5267 \begin_layout Description
5268 Math.lyx a special manual to explain everything regarding math in all detail.
5269 Math.lyx is up to date for \SpecialChar LyX
5270 2.1.x, currently maintained by Uwe Stöhr.
5273 \begin_layout Description
5274 Additional.lyx this manual covers information that would be too much detail
5275 for the UserGuide or would make the UserGuide uncompilable or only compilable
5276 when installing a lot of special \SpecialChar LaTeX
5278 What should be in the UserGuide or better in Additional is a matter of
5280 it is up to you to decide that.
5281 Additional.lyx is not completely up to date for \SpecialChar LyX
5284 \begin_inset space ~
5287 8 is up to date and currently maintained by Uwe Stöhr.
5288 It certainly needs a rewrite and update.
5289 For example many info in chapter
5290 \begin_inset space ~
5293 2 and 3 are already covered by the UserGuide and/or the EmbeddedObjects
5297 \begin_layout Description
5298 Customization.lyx this manual covers information how to customize \SpecialChar LyX
5300 output formats, operating systems, languages etc.
5301 It is currently completely out of date and needs a major rewrite and update.
5302 If you do this please assure that your information are given for all OSes
5303 and \SpecialChar LaTeX
5304 distributions (meaning be as objective as possible).
5307 \begin_layout Chapter
5311 \begin_layout Standard
5312 The aim of this chapter is to serve as a guide for the developers, to aid
5313 us to get clean and uniform code.
5315 We really like to have new developers joining the \SpecialChar LyX
5317 However, we have had problems in the past with developers leaving the project
5318 and their contributed code in a far from perfect state.
5319 Most of this happened before we really became aware of these issues, but
5320 still, we don't want it to happen again.
5321 So we have put together some guidelines and rules for the developers.
5324 \begin_layout Section
5328 \begin_layout Standard
5329 These guidelines should save us a lot of work while cleaning up the code
5330 and help us to have quality code.
5332 has been haunted by problems coming from unfinished projects by people
5333 who have left the team.
5334 Those problems will hopefully disappear if the code is easy to hand over
5336 In general, if you want to contribute to the main source, we expect at
5340 \begin_layout Itemize
5341 the most important rule first: KISS (Keep It Simple Stupid), always use
5342 a simple implementation in favor of a more complicated one.
5343 This eases maintenance a lot.
5346 \begin_layout Itemize
5347 write good C++ code: Readable, well commented and taking advantage of the
5349 Follow the formatting guidelines.
5351 \begin_inset space ~
5355 \begin_inset CommandInset ref
5357 reference "sec:Formatting"
5367 \begin_layout Itemize
5368 adapt the code to the structures already existing in \SpecialChar LyX
5369 , or in the case that
5370 you have better ideas, discuss them on the developer's list before writing
5374 \begin_layout Itemize
5375 take advantage of the C++ standard library.
5376 Especially don't use custom containers when a standard container is usable;
5377 learn to use the algorithms and functors in the standard library.
5380 \begin_layout Itemize
5381 be aware of exceptions and write exception safe code.
5383 \begin_inset space ~
5387 \begin_inset CommandInset ref
5389 reference "sec:Exceptions"
5399 \begin_layout Itemize
5400 document all variables, methods, functions, classes etc.
5401 We are using the source documentation program doxygen, a program that handles
5402 javadoc syntax, to document sources.
5403 You can download doxygen from:
5404 \begin_inset Flex URL
5407 \begin_layout Plain Layout
5409 http://www.stack.nl/~dimitri/doxygen/
5417 \begin_layout Itemize
5418 we have certain code constructs that we try to follow.
5420 \begin_inset space ~
5424 \begin_inset CommandInset ref
5426 reference "sec:Code-constructs"
5436 \begin_layout Section
5440 \begin_layout Standard
5441 It is implicitly understood that all patches contributed to The \SpecialChar LyX
5443 is under the Gnu General Public License, version 2 or later.
5444 If you have a problem with that, don't contribute code.
5445 Also please don't just pop up out of the blue with a huge patch (or small)
5446 that changes something substantial in \SpecialChar LyX
5448 Always discuss your ideas with the developers on the developer's mailing
5450 When you create the patch, please use "
5454 " since we find that a lot easier to read than the other diff formats.
5455 Also please do not send patches that implements or fixes several different
5456 things; several patches is a much better option.
5457 We also require you to provide a commit message entry with every patch,
5458 this describes in detail what the patch is doing.
5462 \begin_layout Section
5464 \begin_inset CommandInset label
5466 name "sec:Code-constructs"
5473 \begin_layout Standard
5474 We have several guidelines on code constructs, some of these exist to make
5475 the code faster, others to make the code clearer.
5476 Yet others exist to allow us to take advantage of the strong type checking
5481 \begin_layout Itemize
5482 Declaration of variables should wait as long as possible.
5483 The rule is: "Don't declare it until you need it." In C++ there are a lot
5484 of user defined types, and these can very often be expensive to initialize.
5485 This rule connects to the next rule too.
5489 \begin_layout Itemize
5490 Declare the variable as const if you don't need to change it.
5491 This applies to POD types like int as well as classes.
5495 \begin_layout Itemize
5496 Make the scope of a variable as small as possible.
5499 \begin_layout Itemize
5500 Make good use of namespaces.
5501 Prefer anonymous namespaces to declaring "static" for file scope.
5504 \begin_layout Itemize
5505 Prefer preincrement to postincrement whenever possible.
5508 \begin_layout Itemize
5509 Preincrement has potential of being faster than postincrement.
5510 Just think about the obvious implementations of pre/post-increment.
5511 This rule applies to decrement too.
5514 \begin_layout Itemize
5516 \begin_inset Separator latexpar
5523 \begin_layout Standard
5524 \begin_inset listings
5525 lstparams "basicstyle={\footnotesize},language={C++}"
5529 \begin_layout Plain Layout
5534 \begin_layout Plain Layout
5544 \begin_layout Standard
5548 \begin_layout Standard
5549 \begin_inset listings
5553 \begin_layout Plain Layout
5555 T++; // not used in LyX
5558 \begin_layout Plain Layout
5560 U--; // not used in LyX
5569 \begin_layout Itemize
5570 Try to minimize evaluation of the same code over and over.
5571 This is aimed especially at loops.
5573 \begin_inset Newline newline
5577 \begin_inset Separator latexpar
5584 \begin_layout Standard
5585 \begin_inset listings
5589 \begin_layout Plain Layout
5591 Container::iterator end = large.end();
5594 \begin_layout Plain Layout
5596 for (Container::iterator it = large.begin(); it != end; ++it) {
5599 \begin_layout Plain Layout
5604 \begin_layout Plain Layout
5614 \begin_layout Standard
5618 \begin_layout Standard
5619 \begin_inset listings
5623 \begin_layout Plain Layout
5625 for (Container::iterator it = large.begin(); it != large.end(); ++it) {
5628 \begin_layout Plain Layout
5633 \begin_layout Plain Layout
5644 \begin_layout Itemize
5645 For functions and methods that return a non-POD type
5649 \begin_layout Plain Layout
5655 T, return T const instead.
5656 This gives better type checking, and will give a compiler warning when
5657 temporaries are used wrongly.
5658 \begin_inset Separator latexpar
5665 \begin_layout Standard
5669 \begin_layout Standard
5670 \begin_inset listings
5674 \begin_layout Plain Layout
5684 \begin_layout Standard
5688 \begin_layout Standard
5689 \begin_inset listings
5693 \begin_layout Plain Layout
5704 \begin_layout Itemize
5705 Avoid using the default cases in switch statements unless you have too.
5706 Use the correct type for the switch expression and let the compiler ensure
5707 that all cases are exhausted.
5710 \begin_layout Itemize
5711 \begin_inset listings
5715 \begin_layout Plain Layout
5720 \begin_layout Plain Layout
5725 \begin_layout Plain Layout
5730 \begin_layout Plain Layout
5735 \begin_layout Plain Layout
5739 \begin_layout Plain Layout
5744 \begin_layout Plain Layout
5748 \begin_layout Plain Layout
5753 \begin_layout Plain Layout
5758 \begin_layout Plain Layout
5763 \begin_layout Plain Layout
5768 \begin_layout Plain Layout
5773 \begin_layout Plain Layout
5778 \begin_layout Plain Layout
5780 // not needed and would shadow a wrong use of Foo
5783 \begin_layout Plain Layout
5788 \begin_layout Plain Layout
5798 \begin_layout Section
5800 \begin_inset CommandInset label
5802 name "sec:Exceptions"
5809 \begin_layout Standard
5810 Be aware of the presence of exceptions.
5811 One important thing to realize is that you often do not have to use throw,
5812 try or catch to be exception safe.
5813 Let's look at the different types of exceptions safety (these are taken
5814 from Herb Sutter's book
5815 \begin_inset CommandInset citation
5825 \begin_layout Enumerate
5826 Basic guarantee: Even in the presence of exceptions thrown by T or other
5827 exceptions, Stack objects don't leak resources.
5828 Note that this also implies that the container will be destructible and
5829 usable even if an exception is thrown while performing some container operation.
5830 However, if an exception is thrown, the container will be in a consistent,
5831 but not necessarily predictable, state.
5832 Containers that support the basic guarantee can work safely in some settings.
5836 \begin_layout Enumerate
5837 Strong guarantee: If an operation terminates because of an exception, program
5838 state will remain unchanged.
5839 This always implies commit-or-rollback semantics, including that no references
5840 or iterators into the container be invalidated if an operation fails.
5841 For example, if a Stack client calls Top and then attempts a Push that
5842 fails because of an exception, then the state of the Stack object must
5843 be unchanged and the reference returned from the prior call to Top must
5845 For more information on these guarantees, see Dave Abrahams's documentation
5846 of the SGI exception-safe standard library adaption at:
5847 \begin_inset Flex URL
5850 \begin_layout Plain Layout
5852 http://www.stlport.org/doc/exception_safety.html
5857 Probably the most interesting point here is that when you implement the
5858 basic guarantee, the strong guarantee often comes for free.
5859 For example, in our Stack implementation, almost everything we did was
5860 needed to satisfy just the basic guarantee – and what's presented above
5861 very nearly satisfies the strong guarantee, with little or no extra work.
5862 Not half bad, considering all the trouble we went to.
5863 In addition to these two guarantees, there is one more guarantee that certain
5864 functions must provide in order to make overall exception safety possible:
5867 \begin_layout Enumerate
5868 No throw guarantee: The function will not emit an exception under any circumstan
5870 Overall exception safety isn't possible unless certain functions are guaranteed
5872 In particular, we've seen that this is true for destructors; later in this
5873 miniseries, we'll see that it's also needed in certain helper functions,
5881 \begin_layout Standard
5882 For all cases where we might be able to write exception safe functions without
5883 using try, throw or catch we should do so.
5884 In particular we should look over all destructors to ensure that they are
5885 as exception safe as possible.
5888 \begin_layout Section
5890 \begin_inset CommandInset label
5892 name "sec:Formatting"
5899 \begin_layout Itemize
5900 Only one declaration on each line.
5901 \begin_inset Separator latexpar
5908 \begin_layout Standard
5912 \begin_layout Standard
5913 \begin_inset listings
5917 \begin_layout Plain Layout
5922 \begin_layout Plain Layout
5932 \begin_layout Standard
5936 \begin_layout Standard
5937 \begin_inset listings
5941 \begin_layout Plain Layout
5943 int a, b; // not used in LyX
5951 \begin_layout Standard
5952 This is especially important when initialization is done at the same time:
5955 \begin_layout Standard
5959 \begin_layout Standard
5960 \begin_inset listings
5964 \begin_layout Plain Layout
5969 \begin_layout Plain Layout
5971 string b = "Gullik";
5979 \begin_layout Standard
5983 \begin_layout Standard
5984 \begin_inset listings
5988 \begin_layout Plain Layout
5990 string a = "Lars", b = "Gullik"; // not used in LyX
5998 \begin_layout Standard
5999 [Note that 'string a = "Lars"' is formally calling a copy constructor on
6000 a temporary constructed from a string literal and therefore has the potential
6001 of being more expensive then direct construction by 'string a("Lars")'.
6002 However the compiler is allowed to elide the copy (even if it had side
6003 effects), and modern compilers typically do so.
6004 Given these equal costs, \SpecialChar LyX
6005 code favours the '=' idiom as it is in line with
6006 the traditional C-style initialization, _and_ cannot be mistaken as function
6007 declaration, _and_ reduces the level of nested parantheses in more initializati
6012 \begin_layout Itemize
6013 Pointers and references:
6014 \begin_inset Separator latexpar
6021 \begin_layout Standard
6025 \begin_layout Standard
6026 \begin_inset listings
6030 \begin_layout Plain Layout
6035 \begin_layout Plain Layout
6045 \begin_layout Standard
6049 \begin_layout Standard
6050 \begin_inset listings
6054 \begin_layout Plain Layout
6056 char *p = "flop"; // not used in LyX
6059 \begin_layout Plain Layout
6061 char &c = *p; // not used in LyX
6069 \begin_layout Standard
6070 Some time ago we had a huge discussion on this subject and after convincing
6071 argumentation from Asger this is what we decided.
6072 Also note that we will have:
6075 \begin_layout Standard
6076 \begin_inset listings
6080 \begin_layout Plain Layout
6090 \begin_layout Standard
6094 \begin_layout Standard
6095 \begin_inset listings
6099 \begin_layout Plain Layout
6101 const char * p; // not used in LyX
6110 \begin_layout Itemize
6111 Operator names and parentheses
6112 \begin_inset Separator latexpar
6119 \begin_layout Standard
6120 \begin_inset listings
6124 \begin_layout Plain Layout
6134 \begin_layout Standard
6138 \begin_layout Standard
6139 \begin_inset listings
6143 \begin_layout Plain Layout
6145 operator == (type) // not used in LyX
6153 \begin_layout Standard
6154 The == is part of the function name, separating it makes the declaration
6155 look like an expression.
6159 \begin_layout Itemize
6160 Function names and parentheses
6161 \begin_inset Separator latexpar
6168 \begin_layout Standard
6169 \begin_inset listings
6173 \begin_layout Plain Layout
6183 \begin_layout Standard
6187 \begin_layout Standard
6188 \begin_inset listings
6192 \begin_layout Plain Layout
6194 void mangle () // not used in LyX
6203 \begin_layout Itemize
6205 \begin_inset Separator latexpar
6212 \begin_layout Standard
6213 \begin_inset listings
6217 \begin_layout Plain Layout
6222 \begin_layout Plain Layout
6227 \begin_layout Plain Layout
6232 \begin_layout Plain Layout
6237 \begin_layout Plain Layout
6247 \begin_layout Standard
6251 \begin_layout Standard
6252 \begin_inset listings
6256 \begin_layout Plain Layout
6258 enum { one = 1, two = 2, three 3 }; // not used in LyX
6266 \begin_layout Standard
6270 \begin_layout Standard
6271 \begin_inset listings
6275 \begin_layout Plain Layout
6280 \begin_layout Plain Layout
6285 \begin_layout Plain Layout
6290 \begin_layout Plain Layout
6295 \begin_layout Plain Layout
6306 \begin_layout Itemize
6308 \begin_inset Separator latexpar
6315 \begin_layout Standard
6316 Using a plain 0 is always correct and least effort to type.
6320 \begin_layout Standard
6321 \begin_inset listings
6325 \begin_layout Plain Layout
6335 \begin_layout Standard
6339 \begin_layout Standard
6340 \begin_inset listings
6344 \begin_layout Plain Layout
6346 void * p = NULL; // not used in LyX
6354 \begin_layout Standard
6358 \begin_layout Standard
6359 \begin_inset listings
6363 \begin_layout Plain Layout
6367 0'; // not used in LyX
6375 \begin_layout Standard
6379 \begin_layout Standard
6380 \begin_inset listings
6384 \begin_layout Plain Layout
6386 void * p = 42 - 7 * 6; // not used in LyX
6394 \begin_layout Standard
6395 Note: As an exception, imported third party code as well as code interfacing
6396 the "native" APIs (src/support/os_*) can use NULL.
6400 \begin_layout Itemize
6401 Naming rules for classes
6402 \begin_inset Separator latexpar
6409 \begin_layout Itemize
6410 Use descriptive but simple and short names.
6414 \begin_layout Itemize
6415 Class names are usually capitalized, and function names lowercased.
6418 \begin_layout Itemize
6419 Enums are named like Classes, values are usually in lower-case.
6422 \begin_layout Itemize
6423 Public API is camel-case ('
6425 void setAFlagToAValue(bool)
6430 \begin_layout Itemize
6431 Members variables are underscored ('
6433 enable_this_feature_flag_
6442 \begin_layout Itemize
6443 Private/protected functions are also camel-case
6446 \begin_layout Itemize
6447 New types are capitalized, so this goes for typedefs, classes, structs and
6452 \begin_layout Itemize
6454 \begin_inset Separator latexpar
6461 \begin_layout Itemize
6462 Adapt the formatting of your code to the one used in the other parts of
6465 In case there is different formatting for the same construct, use the one
6470 \begin_layout Itemize
6471 Use existing structures
6472 \begin_inset Separator latexpar
6479 \begin_layout Itemize
6480 \begin_inset CommandInset label
6482 name "Use-string-wherever"
6486 Use string wherever possible.
6488 will someday move to Unicode, and that will be easy if everybody uses
6490 Unicode strings should prefer using docstring instead of UTF-8 encoded
6494 \begin_layout Itemize
6495 Check out the filename and path tools in filetools.h
6498 \begin_layout Itemize
6499 Check out the string tools in lstring.h.
6502 \begin_layout Itemize
6503 Use the \SpecialChar LyX
6504 Err class to report errors and messages using the lyxerr instantiation.
6505 [add description of other existing structures]
6509 \begin_layout Itemize
6511 \begin_inset Separator latexpar
6518 \begin_layout Itemize
6519 Use this order for the access sections of your class: public, protected,
6521 The public section is interesting for every user of the class.
6522 The private section is only of interest for the implementors of the class
6524 [Obviously not true since this is for developers, and we do not want one
6525 developer only to be able to read and understand the implementation of
6530 \begin_layout Itemize
6531 Avoid declaring global objects in the declaration file of the class.
6532 If the same variable is used for all objects, use a static member.
6535 \begin_layout Itemize
6536 Avoid global or static variables.
6540 \begin_layout Itemize
6542 \begin_inset Separator latexpar
6549 \begin_layout Standard
6550 If you create a new file, the top of the file should look something like
6554 \begin_layout Standard
6555 \begin_inset listings
6559 \begin_layout Plain Layout
6564 \begin_layout Plain Layout
6571 \begin_layout Plain Layout
6573 * This file is part of LyX, the document processor.
6576 \begin_layout Plain Layout
6578 * Licence details can be found in the file COPYING.
6581 \begin_layout Plain Layout
6586 \begin_layout Plain Layout
6593 \begin_layout Plain Layout
6598 \begin_layout Plain Layout
6600 * Full author contact details are available in file CREDITS
6603 \begin_layout Plain Layout
6614 \begin_layout Itemize
6616 \begin_inset Separator latexpar
6623 \begin_layout Itemize
6624 The documentation is generated from the header files.
6627 \begin_layout Itemize
6628 You document for the other developers, not for yourself.
6631 \begin_layout Itemize
6632 You should document what the function does, not the implementation.
6633 \begin_inset Separator latexpar
6640 \begin_layout Itemize
6641 in the .cpp files you document the implementation.
6645 \begin_layout Itemize
6646 Single line description (///), multiple lines description (/** ...
6647 */) see the doxygen webpage referenced above
6651 \begin_layout Section
6652 Naming rules for Lyx User Functions (LFUNs)
6655 \begin_layout Standard
6656 Here is the set of rules to apply when a new command name is introduced:
6659 \begin_layout Enumerate
6660 Use the object.event order.
6661 That is, use `word-forward' instead of`forward-word'.
6664 \begin_layout Enumerate
6665 Don't introduce an alias for an already named object.
6669 \begin_layout Enumerate
6670 Forward movement or focus is called `forward' (not `right').
6673 \begin_layout Enumerate
6674 Backward movement or focus is called `backward' (not `left').
6677 \begin_layout Enumerate
6678 Upward movement of focus is called `up'.
6681 \begin_layout Enumerate
6682 Downward movement is called `down'.
6685 \begin_layout Enumerate
6686 The begin of an object is called `begin' (not `start').
6689 \begin_layout Enumerate
6690 The end of an object is called `end'.
6693 \begin_layout Section
6694 How to create class interfaces
6697 \begin_layout Standard
6698 (a.k.a How Non-Member Functions Improve Encapsulation)
6701 \begin_layout Standard
6702 I recently read an article by Scott Meyers, where he makes a strong case
6703 on how non-member functions makes classes more encapsulated, not less.
6704 Just skipping to the core of this provides us with the following algorithm
6705 for deciding what kind of function to add to a class interface:
6708 \begin_layout Itemize
6709 We need to add a function f to the class C's API.
6710 \begin_inset Separator latexpar
6717 \begin_layout Standard
6718 \begin_inset listings
6722 \begin_layout Plain Layout
6724 if (f needs to be virtual)
6727 \begin_layout Plain Layout
6729 make f a member function of C;
6732 \begin_layout Plain Layout
6734 else if (f is operator>> or operator<<) {
6737 \begin_layout Plain Layout
6739 make f a non-member function;
6742 \begin_layout Plain Layout
6744 if (f needs access to non-public members of C)
6747 \begin_layout Plain Layout
6749 make f a friend of C;
6752 \begin_layout Plain Layout
6754 } else if (f needs type conversions on its left-most argument) {
6757 \begin_layout Plain Layout
6759 make f a non-member function;
6762 \begin_layout Plain Layout
6764 if (f needs access to non-public members of C)
6767 \begin_layout Plain Layout
6769 make f a friend of C;
6772 \begin_layout Plain Layout
6774 } else if (f can be implemented via C's public interface)
6777 \begin_layout Plain Layout
6779 make f a non-member function;
6782 \begin_layout Plain Layout
6787 \begin_layout Plain Layout
6789 make f a member function of C;
6798 \begin_layout Chapter
6799 Coding recommendations
6802 \begin_layout Standard
6803 These are some rules for effective C++ programming.
6804 These are taken from Scott Meyers
6805 \begin_inset CommandInset citation
6812 , and are presented in their short form.
6813 These are not all the rules Meyers presents, only the most important of
6816 does not yet follow these rules, but they should be the goal.
6819 \begin_layout Itemize
6833 \begin_layout Itemize
6834 use the same form in corresponding calls to new and delete, i.e.
6835 write delete[] obj; if new obj[n]; was used to create the object and write
6836 delete obj; if you wrote new obj; Notice strings should be std::string's
6837 instead of char *'s.
6838 (this contradicts to
6839 \begin_inset CommandInset ref
6841 reference "Use-string-wherever"
6848 \begin_layout Itemize
6849 define a default constructor, copy constructor and an assignment operator
6850 for all classes with dynamically allocated memory that are not made noncopyable
6853 \begin_layout Itemize
6854 do not define default constructor, copy constructor and an assignment operator
6855 if the compiler generated one would do the same
6858 \begin_layout Itemize
6859 make destructors virtual in base classes and only there
6862 \begin_layout Itemize
6863 assign to all data members in operator=()
6866 \begin_layout Itemize
6867 strive for class interfaces that are complete and minimal
6870 \begin_layout Itemize
6871 differentiate among member functions, global functions and friend functions
6874 \begin_layout Itemize
6875 avoid data members in the public interface
6878 \begin_layout Itemize
6879 use const whenever possible
6882 \begin_layout Itemize
6883 pass and return objects by reference instead of by value
6886 \begin_layout Itemize
6887 choose carefully between function overloading and parameter defaulting
6890 \begin_layout Itemize
6891 never return a reference to a local object or a dereferenced pointer initialized
6892 by new within the function
6895 \begin_layout Itemize
6896 use enums for integral constants
6899 \begin_layout Itemize
6900 minimize compilation dependencies between files
6903 \begin_layout Itemize
6904 pay attention to compiler warnings
6907 \begin_layout Itemize
6908 differentiate between inheritance of interface and inheritance of implementation
6911 \begin_layout Itemize
6912 differentiate between inheritance and templates
6915 \begin_layout Itemize
6916 ensure that global objects are initialized before they are used
6919 \begin_layout Itemize
6920 avoid conditions to 'if' and 'while' that span more than a line
6923 \begin_layout Chapter
6928 \begin_layout Itemize
6929 And one of mine: (Lgb)
6930 \begin_inset Separator latexpar
6937 \begin_layout Itemize
6938 when switching on enums, refrain from using "default:" if possible
6942 \begin_layout Itemize
6943 And one of mine: (Andre')
6944 \begin_inset Separator latexpar
6951 \begin_layout Itemize
6952 try to implement your class in a way that the automatically generated copy
6953 constructor and copy assignment work out-of-the box
6956 \begin_layout Itemize
6957 I don't have problems with using boost in the implementation _if and only
6958 if_ it provides actual benefits over less intrusive alternatives.
6959 I do have a problem with needlessly sprinkling 'boost::' over interfaces,
6960 especially if it does not add any value.
6961 \begin_inset Separator latexpar
6968 \begin_layout Standard
6969 Given that there seems to be an unconditional "typedef unsigned int quint32;"
6970 in qglobal.h I don't think there's any platform supported by current \SpecialChar LyX
6972 could not use 'unsigned int' (and an static assert in some implementation
6973 file for the unlikely case some ILP64 zombie raises its ugly head again.
6974 And if that happens, using <cstdint> would still be a better choice...)
6977 \begin_layout Standard
6978 The idea is to create something that's not compilable as soon as the condition
6980 There are lots of possibilities to achieve this, some examples follow:
6983 \begin_layout Standard
6984 In C++11 there's a "built-in":
6987 \begin_layout Standard
6988 \begin_inset listings
6992 \begin_layout Plain Layout
6994 static_assert(sizeof(int) == 4, "Funny platform")
7002 \begin_layout Standard
7003 until then on namespace scope:
7006 \begin_layout Standard
7007 \begin_inset listings
7011 \begin_layout Plain Layout
7013 #include <boost/static_assert.hpp> BOOST_STATIC_ASSERT(sizeof(int) == 4)
7021 \begin_layout Standard
7025 \begin_layout Standard
7026 \begin_inset listings
7030 \begin_layout Plain Layout
7032 template<bool Condition> struct static_assert_helper;
7035 \begin_layout Plain Layout
7037 template <> struct static_assert_helper<true> {};
7040 \begin_layout Plain Layout
7042 enum { dummy = sizeof(static_assert_helper<sizeof(int) == 4>)};
7050 \begin_layout Standard
7051 or somewhat brutish without templates, in any function:
7054 \begin_layout Standard
7055 \begin_inset listings
7059 \begin_layout Plain Layout
7061 const int d = sizeof(int) - 4;
7064 \begin_layout Plain Layout
7069 \begin_layout Plain Layout
7074 \begin_layout Plain Layout
7079 \begin_layout Plain Layout
7084 \begin_layout Plain Layout
7094 \begin_layout Standard
7095 Any of them in a .cpp file will break compilation as soon as sizeof(int)
7097 Personally I prefer something like the third version (or the first, if
7098 using C++11 is allowed).
7103 \begin_layout Itemize
7104 And one of mine: (vfr)
7105 \begin_inset Separator latexpar
7112 \begin_layout Itemize
7114 \begin_inset Flex URL
7117 \begin_layout Plain Layout
7119 http://www.lyx.org/trac/changeset/35855
7125 \begin_inset Separator latexpar
7132 \begin_layout Standard
7133 A dynamic_cast is necessary when:
7136 \begin_layout Itemize
7137 the object to be casted is from an external library because we can't add
7138 Qxxx::asXxxx() to Qt e.g.:
7139 \begin_inset Separator latexpar
7146 \begin_layout Itemize
7147 QAbstractListModel to GuiIdListModel,
7150 \begin_layout Itemize
7151 QValidator to PathValidator,
7154 \begin_layout Itemize
7155 QWidget to TabWorkArea,
7158 \begin_layout Itemize
7159 QWidget to GuiWorkArea;
7163 \begin_layout Itemize
7164 the object is to be casted from an interface to the implementing class,
7165 because the Interface does not know by whom it is implemented:
7166 \begin_inset Separator latexpar
7173 \begin_layout Itemize
7174 ProgressInterface to GuiProgress,
7177 \begin_layout Itemize
7178 Application to GuiApplication.
7182 \begin_layout Standard
7183 A dynamic_cast can be replaced by:
7186 \begin_layout Itemize
7187 already existing as***Inset() functions, e.g.:
7188 \begin_inset Separator latexpar
7195 \begin_layout Itemize
7199 \begin_layout Itemize
7200 asInsetMath()->asMacro(),
7203 \begin_layout Itemize
7208 \begin_layout Itemize
7209 A static_cast when we are sure this can't go wrong, e.g.:
7210 \begin_inset Separator latexpar
7217 \begin_layout Itemize
7218 we are sure that CellData::inset->clone() is an InsetTableCell,
7221 \begin_layout Itemize
7222 in cases where we explicitly check it->lyxCode().
7228 \begin_layout Bibliography
7229 \begin_inset CommandInset bibitem
7230 LatexCommand bibitem
7238 Effective C++, 50 Specific Ways to Improve Your Programs and Design.
7239 Addison-Wesley, 1992
7242 \begin_layout Bibliography
7243 \begin_inset CommandInset bibitem
7244 LatexCommand bibitem
7251 Exceptional C++: 47 engineering puzzles, programming problems, and solutions.
7255 \begin_layout Bibliography
7256 \begin_inset CommandInset bibitem
7257 LatexCommand bibitem
7263 Scott Meyers, C/C++ User's Journal (Vol.18,No.2)