@@ -98,6 +98,14 @@ function package.declareSettings (_)
9898 default = " chicago" ,
9999 help = " BibTeX style" ,
100100 })
101+
102+ -- For CSL hanging-indent or second-field-align
103+ SILE .settings :declare ({
104+ parameter = " bibliography.indent" ,
105+ type = " measurement" ,
106+ default = SILE .types .measurement (" 3em" ),
107+ help = " Left indentation for bibliography entries when the citation style requires it." ,
108+ })
101109end
102110
103111--- Retrieve the CSL engine, creating it if necessary.
@@ -279,6 +287,18 @@ function package:registerCommands ()
279287 end )
280288 end )
281289
290+ self :registerCommand (" bibBoxForIndent" , function (_ , content )
291+ local hbox = SILE .typesetter :makeHbox (content )
292+ local margin = SILE .types .length (SILE .settings :get (" bibliography.indent" ):absolute ())
293+ if hbox .width > margin then
294+ SILE .typesetter :pushHbox (hbox )
295+ SILE .typesetter :typeset (" " )
296+ else
297+ hbox .width = margin
298+ SILE .typesetter :pushHbox (hbox )
299+ end
300+ end )
301+
282302 -- Style and locale loading
283303
284304 self :registerCommand (" bibliographystyle" , function (options , _ )
@@ -390,9 +410,31 @@ function package:registerCommands ()
390410 end
391411
392412 print (" <bibliography: " .. # entries .. " entries>" )
413+ if not SILE .typesetter :vmode () then
414+ SILE .call (" par" )
415+ end
393416 local engine = self :getCslEngine ()
394417 local cite = engine :reference (entries )
395- SILE .processString ((" <sile>%s</sile>" ):format (cite ), " xml" )
418+ SILE .settings :temporarily (function ()
419+ local hanging_indent = SU .boolean (engine .bibliography .options [" hanging-indent" ], false )
420+ local must_align = engine .bibliography .options [" second-field-align" ]
421+ local lskip = (SILE .settings :get (" document.lskip" ) or SILE .types .node .glue ()):absolute ()
422+ if hanging_indent or must_align then
423+ -- Respective to the fixed part of the current lskip, all lines are indented
424+ -- but the first one.
425+ local indent = SILE .settings :get (" bibliography.indent" ):absolute ()
426+ SILE .settings :set (" document.lskip" , lskip .width + indent )
427+ SILE .settings :set (" document.parindent" , - indent )
428+ SILE .settings :set (" current.parindent" , - indent )
429+ else
430+ -- Fixed part of the current lskip, and no paragraph indentation
431+ SILE .settings :set (" document.lskip" , lskip .width )
432+ SILE .settings :set (" document.parindent" , SILE .types .length ())
433+ SILE .settings :set (" current.parindent" , SILE .types .length ())
434+ end
435+ SILE .processString ((" <sile>%s</sile>" ):format (cite ), " xml" )
436+ SILE .call (" par" )
437+ end )
396438
397439 SILE .scratch .bibtex .cited = { keys = {}, citnums = {} }
398440 end , " Produce a bibliography of references." )
0 commit comments