public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Table of Contents Insertion
@ 2021-12-09 14:17 Chad Samsel
       [not found] ` <09cc470d-3c03-4d79-bc47-7158080a9413n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Chad Samsel @ 2021-12-09 14:17 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 138 bytes --]

I know that pandoc creates a table of contents when the .docx file is 
created but it doesn't insert it. How would I go about doing that?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Table of Contents Insertion
       [not found] ` <09cc470d-3c03-4d79-bc47-7158080a9413n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2021-12-09 16:47   ` 'Nick Bart' via pandoc-discuss
  2021-12-09 17:36     ` Chad Samsel
  0 siblings, 1 reply; 3+ messages in thread
From: 'Nick Bart' via pandoc-discuss @ 2021-12-09 16:47 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 2458 bytes --]

AFAIK, pandoc can only insert a placeholder for a ToC into a docx document, but not create a full ToC itself.

The latter requires opening the document in MS Word, LibreOffice or a similar program and updating the ToC manually. (In LibreOffice, the menu command is Tools > Update > Update All; MS Word instructions are at https://support.microsoft.com/en-us/office/update-a-table-of-contents-6c727329-d8fd-44fe-83b7-fa7fe3d8ac7a.)

Updating from the command line is possible, too (at least when using LibreOffice [LO]).

This involves a macro like the following (which borrows ideas from https://ask.libreoffice.org/t/how-to-automatically-update-indices-in-headless-mode/11878), saved in LO under, e.g., "Standard.Module2.UpdateAllIndexes":

```
sub UpdateAllIndexes(sDocUrl as string)

dim oDocument as object
dim dispatcher as object

dim propExp(0) as new com.sun.star.beans.PropertyValue

dim sNewUrl as string

Dim FileProperties(1) As New com.sun.star.beans.PropertyValue
FileProperties(0).Name = "Hidden"
FileProperties(0).Value = True

if fileExists(sDocUrl) then
oDocument = starDesktop.loadComponentFromUrl(convertToUrl(sDocUrl), "_blank", 0, FileProperties())
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(oDocument.CurrentController.Frame, ".uno:UpdateAllIndexes", "", 0, Array())
GlobalScope.BasicLibraries.LoadLibrary("Tools")
propExp(0).Name = "FilterName"
propExp(0).Value = "MS Word 2007 XML"
sNewUrl = GetFileNameWithoutExtension(sDocUrl) & "_updated.docx"
oDocument.storeToURL(convertToUrl(sNewUrl), propExp())
end if

end sub
```

This macro can then be run from the command line (the following works on macOS):

```
/Applications/LibreOffice.app/Contents/MacOS/soffice --invisible --nofirststartwizard --headless --norestore "macro:///Standard.Module2.UpdateAllIndexes(/full/path/to/file.docx)"
```

… creating a new file `/full/path/to/file_updated.docx`.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/I80KhRRTIZtqDS6YtSd0sn82PQLGziJEjj2sjDDddOo_KTaCx9bTm1rY-DJsxjJSc2ymofEp2QHoQ6hyzN1y46N0No6jor8j_oMBYWEdDjM%3D%40protonmail.com.

[-- Attachment #2: Type: text/html, Size: 3779 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Table of Contents Insertion
  2021-12-09 16:47   ` 'Nick Bart' via pandoc-discuss
@ 2021-12-09 17:36     ` Chad Samsel
  0 siblings, 0 replies; 3+ messages in thread
From: Chad Samsel @ 2021-12-09 17:36 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3053 bytes --]

So I have some script that runs in Jenkins from GitLab that will pull 
multiple .md's together into one .docx. Pandoc will automatically create a 
table of contents. I know this because I can enable the navigation pane and 
see all the headers. If I don't run the --toc then I have to manually 
insert a table of contents and it appears. If I add the --toc it will 
appear automatically after I enable features.[image: toc1.JPG]

On Thursday, December 9, 2021 at 10:47:39 AM UTC-6 Nick Bart wrote:

> AFAIK, pandoc can only insert a placeholder for a ToC into a docx 
> document, but not create a full ToC itself.
>
> The latter requires opening the document in MS Word, LibreOffice or a 
> similar program and updating the ToC manually. (In LibreOffice, the menu 
> command is Tools > Update > Update All; MS Word instructions are at 
> https://support.microsoft.com/en-us/office/update-a-table-of-contents-6c727329-d8fd-44fe-83b7-fa7fe3d8ac7a
> .)
>
> Updating from the command line is possible, too (at least when using 
> LibreOffice [LO]).
>
> This involves a macro like the following (which borrows ideas from 
> https://ask.libreoffice.org/t/how-to-automatically-update-indices-in-headless-mode/11878), 
> saved in LO under, e.g., "Standard.Module2.UpdateAllIndexes":
>
> ```
> sub UpdateAllIndexes(sDocUrl as string)
>
> dim oDocument as object
> dim dispatcher as object
>
> dim propExp(0) as new com.sun.star.beans.PropertyValue
>
> dim sNewUrl as string
>
>   Dim FileProperties(1) As New com.sun.star.beans.PropertyValue
>   FileProperties(0).Name = "Hidden"
>   FileProperties(0).Value = True
>  
> if fileExists(sDocUrl) then
>   oDocument = starDesktop.loadComponentFromUrl(convertToUrl(sDocUrl), 
> "_blank", 0, FileProperties())
>   dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
>   dispatcher.executeDispatch(oDocument.CurrentController.Frame, 
> ".uno:UpdateAllIndexes", "", 0, Array())
>   GlobalScope.BasicLibraries.LoadLibrary("Tools")
>   propExp(0).Name = "FilterName"
>   propExp(0).Value = "MS Word 2007 XML"
>   sNewUrl = GetFileNameWithoutExtension(sDocUrl) & "_updated.docx"
>   oDocument.storeToURL(convertToUrl(sNewUrl), propExp())
> end if
>
> end sub
> ```
>
> This macro can then be run from the command line (the following works on 
> macOS):
>
> ```
> /Applications/LibreOffice.app/Contents/MacOS/soffice --invisible 
> --nofirststartwizard --headless --norestore 
> "macro:///Standard.Module2.UpdateAllIndexes(/full/path/to/file.docx)"
> ```
>
> … creating a new file `/full/path/to/file_updated.docx`.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e2d76284-9963-41cc-8ac1-baa25779a272n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 5294 bytes --]

[-- Attachment #2: toc1.JPG --]
[-- Type: image/jpeg, Size: 46087 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-12-09 17:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09 14:17 Table of Contents Insertion Chad Samsel
     [not found] ` <09cc470d-3c03-4d79-bc47-7158080a9413n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-12-09 16:47   ` 'Nick Bart' via pandoc-discuss
2021-12-09 17:36     ` Chad Samsel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).