Why h function make list or enum so weird?

#list[#h(1em,weak: true)$1/2$

test]

#show math.equation.where(block:false): it=>h(1em,weak: true) + it 

#list[$1/2$

test]

A list item has a body-indent that adds space between the list marker and the text of that list item. When the first thing in that list item body is a weak space, that weak space is ignored since there is already a space.

Effect of body-indent:

#let test-body = [$1/2$

test]

Normal `body-indent`
#list[#h(1em,weak: true)#test-body]
Adjusted `body-indent`
#list(body-indent: 5em)[#h(1em,weak: true)#test-body]

My guess as to why your second part does work is that when the list part of the layouting happens, the body of the list item doesn’t yet include the weak space. This is added afterwards when the show rule is applied to the equation.
Here’s your code again but with an added show rule that let’s us hover our mouse over it to see what values end up there.

#show list: it => it

#list[#h(1em,weak: true)$1/2$

test]

#show math.equation.where(block:false): it=>h(1em,weak: true) + it
#list[$1/2$

test]

The important part here are the parts within each children: ( section (highlighted in the blue rectangles). The first list includes a child that starts with a weak space. The second list that gets process has no weak space, just an equation.

2 Likes

Thank you for your reply. Is there any way to solve this problem?

Depends what you are trying to achieve but removing the weak argument would do it.

I think this is a bug, you can take a look at this post

I think I finally understand that it’s the math part that you are saying is incorrect. What you want to happen is a weak space applied to the equation to collapse just like the weak space in markdown mode is.

In that case my last suggestion doesn’t work at all and I’m not sure how to achieve it.

Maybe there’s some way for the show rule to detect it’s within a list item. Then use that as a signal to not insert a space. But I don’t know how.