Browse Source

LaTeX: Fix handling of missing movements, critical reports

# Conflicts:
#	latex/kaysermake.lua
Urs Liska 1 year ago
parent
commit
3ab99e201d
2 changed files with 28 additions and 12 deletions
  1. 1
    1
      config/latex-templates.lua
  2. 27
    11
      latex/kaysermake.lua

+ 1
- 1
config/latex-templates.lua View File

@@ -103,7 +103,7 @@ TEMPLATES.critical_report = [[
103 103
 
104 104
 
105 105
 TEMPLATES.critical_report_mvt = [[
106
-\subsection*{<<<key>>>}
106
+\subsection*{<<<title>>>}
107 107
 
108 108
 \textbf{Kritische Anmerkungen:}
109 109
 

+ 27
- 11
latex/kaysermake.lua View File

@@ -143,12 +143,17 @@ function content.make_movement_reports()
143 143
   local result = {}
144 144
   for i, mvt in ipairs(META.work.movements) do
145 145
     print(mvt)
146
-    table.insert(result,
147
-      util.replace(TEMPLATES.critical_report_mvt, {
148
-        ['title'] = META.movements[mvt].title,
149
-        ['key'] = META.movements[mvt].title,
150
-        ['style'] = 'default'
151
-      }))
146
+    if META.movements[mvt]
147
+    then
148
+      table.insert(result,
149
+        util.replace(TEMPLATES.critical_report_mvt, {
150
+          ['title'] = META.movements[mvt].title,
151
+          ['key'] = CONFIG.options.target..'.'..mvt,
152
+          ['style'] = 'default'
153
+        }))
154
+    else
155
+      print('Registered in metadata, but not present on disk')
156
+    end
152 157
   end
153 158
   VOLUME.movement_reports = table.concat(result, '\n')
154 159
 end
@@ -459,7 +464,12 @@ end
459 464
 -- returns a table with all key=value pairs (values as single strings).
460 465
 function meta.read_file(file_name, function_name)
461 466
   local metadata = {}
462
-  local content = util.read_file(file_name)
467
+  local content = util.read_file(file_name, '')
468
+  if content == ''
469
+  then
470
+    -- metadata file not found
471
+    return nil
472
+  end
463 473
   local with_expression, _ = util.split_with_block(content, function_name)
464 474
   if not with_expression then error(string.format([[
465 475
 No function \%s found in file %s.]], function_name, file_name))
@@ -498,9 +508,15 @@ end
498 508
 function meta.read_movement_metadata(key)
499 509
   local movement_meta = meta.read_file(
500 510
     repo.work_path()..key..'/metadata.ily', 'setMovementMetadata')
501
-  return {
502
-    ['title'] = movement_meta.title
503
-  }
511
+  if movement_meta
512
+  then
513
+    return {
514
+      ['title'] = movement_meta.title,
515
+      ['key-label'] = movement_meta['key-label'],
516
+      ['key-tonic'] = movement_meta['key-tonic'],
517
+      ['key-mode'] = movement_meta['key-mode'],
518
+    }
519
+  end
504 520
 end
505 521
 
506 522
 
@@ -984,7 +1000,7 @@ function util.read_file(file_name, default)
984 1000
     f:close()
985 1001
     return content
986 1002
   else
987
-    if default then return default else
1003
+    if default ~= nil then return default else
988 1004
       err(string.format([[File %s not found]], file_name))
989 1005
     end
990 1006
   end