Numbered lists that share numbering across sections - asciidoc

In Asciidoctor, is it possible to have multiple numbered lists, split across different sections, that all share numbering (perhaps by setting [start={counter:list-counter}]). Something like this:
== Section A
. item 1
. item 2
== Section B
[start={list-counter}]
. item 3
. item 4
== Section C
[start={list-counter}]
. item 5
. item 6
which should render as this:
Section A
1. item 1
2. item 2
Section B
3. item 3
4. item 4
Section C
5. item 5
6. item 6
Unfortunately I don't think there's a way to have a variable that counts the number of previous list items. Or is there?
I could hack this by placing a [.invisible]#{counter:list-counter}# on every list item, but hopefully there is a better way.

Continuing a list over multiple section is not a standard task, I think the clean way to go is definitely with a counter.
Instead of an ordered list you could instead use a Description list, it does not look the same but brings some flexibility and the main idea is there:
== Section A
{counter:list-counter}):: item 1
{counter:list-counter}):: item 2
== Section B
{counter:list-counter}):: item 3
{counter:list-counter}):: item 4
== Section C
{counter:list-counter}):: item 5
{counter:list-counter}):: item 6

Here's another hack:
= Document
== Section A
. item 1
. item 2
+
[discrete]
== Section B
. item 3
. item 4
+
[discrete]
== Section C
. item 5
. item 6
That gets the list items to have the correct item numbers, but the "discrete" headings are indented. You could use some CSS customization (say via docinfo files) to outdent them.

Related

Nested level logic

I have to write a logic for a problem and use it on a landing page. I am unable to write it.
1 - IT 1
2 - IT 1
3 - IT 1
4 - IT 2
5 - IT 2
6 - IT 2
7 - IT 2
8 - IT 3
9 - IT 4
Problem Statement:
-Till someone is selecting 1 or 2 or 3, only IT 1 is suggested
-When someone chooses 4 or 5 or 6 or 7 and anything with value 3 or below , IT 2 is suggested
-When someone chooses 8 or or 8 + anything below 8 then IT 3 is suggested
-When someone chooses 9 and anything with a value below 9 then IT 4 is suggested.
I was using if condition but it seems that whenever IT2 is satisfied IT3 is also satisfied. How to write the logic?
https://jsfiddle.net/bhanusingh/7fxet35h/9/
Don't nest your ifs. Just write four ifs like in your problem description and make a helper function to make it easier to read.
Below is a pseudo code where numbers represent references to checkboxes. isAnySelected is a helper function that takes a list of checkbox references and returns true if any of those checkboxes are checked.
if (isAnySelected([1,2,3]) )
return IT1
if (isAnySelected([4,5,6,7]) AND isAnySelected([1,2,3]) )
return IT2
if (isAnySelected([8]) AND NOT isAnySelected([9]))
return IT3
if (isAnySelected([9]) AND isAnySelected([1,2,3,4,5,6,7,8]))
return IT4
Note that I added "not 9" rule to #3 so that 8 and 9 selected produces IT4
Solved on Reddit: https://www.reddit.com/r/learnprogramming/comments/bpukvf/i_got_a_very_complex_problem_for_me_i_can_only/enxst62?utm_source=share&utm_medium=web2x

Issue with comparing 2 objects

I have 2 objects to be compared, when the first object contains a newly added element, after compare the two object difference should be showing one as difference.
i.e., object 1 as 3 data elements in the list, object 2 as 3 data elements in the list, now for object 1 a new elemts is added to the first position, when comparing it should have returned in the difference only the newly added elements, but all 3 elements shows as changed and last one as added.
Seems when index is changed the issue is appearing
Example below :
Original List
1
2
3
Modified List
0
1
2
3
Actual Result :
Value Changes as 1 -> 0 ,2 -> 1, 3 -> 2
Newly Added as 3
Expected Result
Newly added 0
, i tried with latest version javers-4.0.0-RC3, still same result .
Please suggest.
Answer to your question is the Javers doc
https://javers.org/documentation/diff-configuration/#list-algorithms

Referencing macro values by index

I defined the macros below as levels of the variables id, var1 and var2:
levelsof id, local(id_lev) sep(,)
levelsof var1, local(var1_lev) sep(,)
levelsof var2, local(var2_lev) sep(,)
I'd like to be able to reference the level values stored in these macros by their index during foreach and forval loops. I'm learning how to use macros, so I'm not sure if this is possible.
When I try to access a single element of any of the above macros, every element of the macro is displayed. For example, if I display the first element of id_lev, every element is displayed as a single element (and, the last element is listed as an invalid name which I don't understand):
. di `id_lev'[1]
0524062407240824092601260226032604 invalid name
r(198);
Furthermore, if I attempt to refer to elements of any of the macros in a loop (examples of what I've tried given below), I receive the error that the third value of the list of levels is an invalid number.
foreach i of numlist 1/10 {
whatever `var1'[i] `var2'[i], gen(newvar)
}
forval i = 1/10 {
local var1_ `: word `i' of `var1''
local var2_ `: word `i' of `var2''
whatever `var1_' `var2_', gen(newvar)
}
Is it not possible to reference elements of a macro by its index?
Or am I referencing the index values incorrectly?
Update 1:
I've gotten everything to work (thank you), save for adapting the forval loop given in William's answer to my loops above in which I am trying to access the macros of two variables at the same index value.
Specifically, I want to call on the first, second, ..., last elements of var1 and var2 simultaneously so that I can use the elements in a loop to produce a new variable. How can I adapt the forval loop suggested by William to accomplish this?
Update 2:
I was able to adapt the code given by William below to create the functioning loop:
levelsof id, clean local(id_lev)
macro list _id_lev
local nid_lev : word count `id_lev'
levelsof var1, local(var1_lev)
macro list _var1_lev
local nvar1_lev : word count `var1_lev'
levelsof var2, local(var2_lev)
macro list _var2_lev
local nvar2_lev : word count `var2_lev'
forval i = 1/`nid_lev' {
local id : word `i' of `id_lev'
macro list _id
local v1 : word `i' of `var1_lev'
macro list _v1
local v2 : word `i' of `var2_lev'
macro list _v2
whatever `v1' `v2', gen(newvar)
}
You will benefit, as I mentioned in my closing remark on your previous question, from close study of section 18.3 of the Stata User's Guide PDF.
sysuse auto, clear
tab rep78, missing
levelsof rep78, missing local(replvl)
macro list _replvl
local numlvl : word count `replvl'
macro list _numlvl
forval i = 1/`numlvl' {
local level : word `i' of `replvl'
macro list _level
display `level'+1000
}
yields
. sysuse auto, clear
(1978 Automobile Data)
. tab rep78, missing
Repair |
Record 1978 | Freq. Percent Cum.
------------+-----------------------------------
1 | 2 2.70 2.70
2 | 8 10.81 13.51
3 | 30 40.54 54.05
4 | 18 24.32 78.38
5 | 11 14.86 93.24
. | 5 6.76 100.00
------------+-----------------------------------
Total | 74 100.00
. levelsof rep78, missing local(replvl)
1 2 3 4 5 .
. macro list _replvl
_replvl: 1 2 3 4 5 .
. local numlvl : word count `replvl'
. macro list _numlvl
_numlvl: 6
. forval i = 1/`numlvl' {
2. local level : word `i' of `replvl'
3. macro list _level
4. display `level'+1000
5. }
_level: 1
1001
_level: 2
1002
_level: 3
1003
_level: 4
1004
_level: 5
1005
_level: .
.

How to markdown nested list items in Bitbucket?

I'm trying to see my markdown nested list items rendered with corresponding indentation when viewed in a browser live from the Bitbucket pages. But I can't figure out how it works even when using their examples (updated):
* Item 1
* Item 2
* Item 3
* Item 3a
* Item 3b
* Item 3c
It ignores indentation for items 3a-c:
I want it to look like this (syntax works perfectly fine on SE and Github):
Their list in list example is particularly unacceptable:
1. Step 1
2. Step 2
3. Step 3
* Item 3a
* Item 3b
* Item 3c
Here's a repo I set up just for this.
Use 4 spaces.
# Unordered list
* Item 1
* Item 2
* Item 3
* Item 3a
* Item 3b
* Item 3c
# Ordered list
1. Step 1
2. Step 2
3. Step 3
1. Step 3.1
2. Step 3.2
3. Step 3.3
# List in list
1. Step 1
2. Step 2
3. Step 3
* Item 3a
* Item 3b
* Item 3c
Here's a screenshot from that updated repo:
Thanks #Waylan, your comment was exactly right.
4 spaces do the trick even inside definition list:
Endpoint
: `/listAgencies`
Method
: `GET`
Arguments
: * `level` - bla-bla.
* `withDisabled` - should we include disabled `AGENT`s.
* `userId` - bla-bla.
I am documenting API using BitBucket Wiki and Markdown proprietary extension for definition list is most pleasing (MD's table syntax is awful, imaging multiline and embedding requirements...).
Possibilities
It is possible to nest a bulleted-unnumbered list into a higher numbered list.
But in the bulleted-unnumbered list the automatically numbered list will not start: Its is not supported.
To start a new numbered list after a bulleted-unnumbered one, put a piece of text between them, or a subtitle: A new numbered list cannot start just behind the bulleted: The interpreter will not start the numbering.
In practice
Dog
German Shepherd - with only a single space ahead.
2. Belgian Shepherd - max 4 spaces ahead.
Number in front of a line interpreted as a "numbering bullet", so making the indentation.
* ..and ignores the written digit: Places/generates its own, in compliance with the structure.
* So it is OK to use only just "1" ones, to get your numbered list.
* Or whatever integer number, even of more digits: The list numbering will continue by increment ++1.
* However, the first item in the numbered list will be kept, so the first leading will usually be the number "1".
Malinois - 5 spaces makes 3rd level already.
MalinoisB - 5 spaces makes 3rd level already.
Groenendael - 8 spaces makes 3rd level yet too.
Tervuren - 9 spaces for 4th level - Intentionaly started by "55".
TervurenB - numbered by "88", in the source code.
Cat
Siberian;
a. SiberianA - problem reproduced: Letters (i.e. "a" here) not recognized by the interpreter as "numbering".
No matter, that it is indented to its separated line in its source code: The indentation is ignored here.
2. Siamese
a. so written manually as a workaround misusing bullets, unnumbered list.
This worked for me in Bitbucket Cloud.
Entering this:
* item a
* item b
** item b1
** item b2
* item3
I've got this:
Even a single space works
...Just open this answer for edit to see it.
Nested lists, deeper levels:
---- leave here an empty row
* first level A item - no space in front the bullet character
* second level Aa item - 1 space is enough
* third level Aaa item - 5 spaces min
* second level Ab item - 4 spaces possible too
* first level B item
Nested lists, deeper levels:
first level A item - no space in front the bullet character
second level Aa item - 1 space is enough
third level Aaa item - 5 spaces min
second level Ab item - 4 spaces possible too
first level B item
Nested lists, deeper levels:
...Skip a line and indent eight spaces. (as said in the editor-help, just on this page)
* first level A item - no space in front the bullet character
* second level Aa item - 1 space is enough
* third level Aaa item - 5 spaces min
* second level Ab item - 4 spaces possible too
* first level B item

Drop all obs of group if condition is met

suppose I have the following panel data (didn't include time var for simplicity)
clear
input id var
1 .
1 0
1 0
1 .
2 .
2 .
2 .
2 .
3 1
3 .
3 .
3 0
end
I would like to delete all groups that have all missing data in their group, that is, I want my data to be like:
id var
1 .
1 0
1 0
1 .
3 1
3 .
3 .
3 0
I tried doing a gen todrop = var[_N], but for some reason, for some groups it doesn't work. Any thoughts? I thought about sorting id var, then doing a cascade replace, but I'm sure there is a better way to do this.
In general, you can verify whether all observations hold the same value by checking first and last observations in each panel, after appropriate sorting. The same principle applies here. I'll use the missing() function:
clear
set more off
input id myvar
1 .
1 0
1 0
1 .
2 .
2 .
2 .
2 .
3 1
3 .
3 .
3 0
end
bysort id (myvar) : gen todrop = missing(myvar[1]) & missing(myvar[_N])
list, sepby(id)
In this case, just checking the first one also works. If it's missing, all others are.
See help by.
Roberto has provided a solution which is however case specific and might lead to wrong outcome.
In fact, suppose you have an observation as follows:
id myvar
2 .
2 1
2 .
Using Roberto's code, you would remove this group, while in the question you need to remove only if all observations are missing.
Therefore I suggest you use a different approach, as follows:
levels id, local(groups) // creates unique values for id (no need to egen if you don't really have to)
foreach iter of local groups {
mdesc myvar if id == "`iter'" // use mdesc and put double quotes if id is a string
drop if id == "`iter'" & r(percent) == 100 // r(percent) is stored after mdesc
}
Roberto's code definitely works. Also does below code. The only contribution is that the original order (sort) of observations is kept if you might want it.
egen todrop2 = min(missing(myvar)), by(id)

Resources