I am having trouble with keeping my figure numbers in the manuscript with their citing order along with the final list of figures and figure legends frustrating since I am managing my entire results portion with putdocx in do files.
Sometimes I choose to delete a figure and find myself scrolling through a lengthy do file trying to finding the in-text citations to the figures and adjusting the numbers. What I want is a bibliography software-type adjustment of numbering the figures and their corresponding legends via locals. I got as far as to craft a way to create a header for figures, figure legends and table as well as table legends with locals as below.
But I am at a loss for extending this code to handle a situation when I choose to delete one figure and having numbers adjust automatically in-text and in final list with the legends. While my final use case will be in putdocx, I have illustrated below with display commands so it is reproducible for anybody in this forum trying to solve this. For all bibliography, I am using Endnote and the Endnote field codes don't interfere with anything in the putdocx statements. I don't want to resort to managing images and tables via Endnote since that is more work.
Sometimes I choose to delete a figure and find myself scrolling through a lengthy do file trying to finding the in-text citations to the figures and adjusting the numbers. What I want is a bibliography software-type adjustment of numbering the figures and their corresponding legends via locals. I got as far as to craft a way to create a header for figures, figure legends and table as well as table legends with locals as below.
But I am at a loss for extending this code to handle a situation when I choose to delete one figure and having numbers adjust automatically in-text and in final list with the legends. While my final use case will be in putdocx, I have illustrated below with display commands so it is reproducible for anybody in this forum trying to solve this. For all bibliography, I am using Endnote and the Endnote field codes don't interfere with anything in the putdocx statements. I don't want to resort to managing images and tables via Endnote since that is more work.
Code:
// Objective: create calls for figure numbers, figure text and short in-manuscript calls to each figure // If figure 1 is deleted or switched with 2 before 1, in-text relative reference numbers to figures and final lists should adjust themselves to accordingly. // Define short unique calls to each figure legend text for the three figures to be used in body of manuscript *------------------------------------------------------- // Objective: create calls for figure numbers, figure text and short in-manuscript calls to each figure // If figure 1 is deleted or switched with 2 before 1, in-text relative reference numbers to figures and final lists should adjust themselves to accordingly. // Define short unique calls to each figure legend text for the three figures to be used in body of manuscript *------------------------------------------------------- local os2 "(see Fig. 1)" local ngs "(see Fig. 2)" local km4 "(see Fig. 3)" local tbdemo "(see Table 1)" // Get the blocks of text for each figure or table legend into a token *------------------------------------------------------------------------------------- tokenize `" "os2text" "ngstext" "km4text" "tbl1text"' /// each will be large blocks of text nearly 100 words // Generate Figure legend list *------------------------------------- local leglist ""Figure 1", "Figure 2", "Figure 3"" local snum 4 forvalues i = 1/`snum' { gettoken Figure`i' leglist : leglist , parse(",") gettoken comma leglist : leglist , parse(",") } // Generate Table legend list *------------------------------------ local tblist ""Table 1" "Table 2"" local tnum 2 forvalues i = 1/`tnum' { gettoken Table`i' tblist : tblist , parse(",") gettoken comma tblist : tblist , parse(",") } // Manuscript body calling figures and tables in order *----------------------------------------------------- di "This is a block with in-text short call to demographic table `tbdemo', the overall survival plot of the entire cohort `os2' and then to the ngs data `ngs' and then to `km4' in this order. What I want is if I delete the local ngs call up there (i.e. the local ngs and the tokenized ngstext), I want os2 `os2' and the km plot figure `km4' renumbered automatically to figures 1 and 2 while Figure 3 below gets deleted from the list of legends." // Final list of Figures and legends *------------------------------------------- display "`Figure1': `1'" display "`Figure2': `2'" display "`Figure3': `3'" display "`Table1' : `4'"