#Testing whether a value is equal to sym.dots

1 messages · Page 1 of 1 (latest)

idle oak
#

I have the following function to construct a list. Problem is, the comparison against ... doesn't work. How can I do that?

#let list(..xs) = {
  let xs = xs.pos()
  for (i, x) in xs.enumerate() {
    if i > 0 {
      if xs.at(i - 1) == $...$ {
        thin
      } else {
        $thin . thin$
      }
    }
    x
  }
}

$list(n_0, n_1, s) \
list(..., n_0, n_1, s) \
list(n_0, ..., n_m, s) \
list(n_0, n_1, ..., s) \
list(n_0, n_1, s, ...) \
list(n_0, ..., n_m, ..., s) \
list(..., n_0, n_1, s, ...) \
$
#

I want it to render as such:

#
#{$...$ == $...$} => true
#let test(x) = x == $...$
$test(...)$ => false
#let test(x) = x == sym.dots
$test(...)$ => false
fervent path
#

Here is my suggestion: because symbols with multiple meanings (such as dots.h,eqetc) may be difficult to identify, we can explicitly compare them using the str function, e.g., str(x) == str("\u{2026}").

#

?r t=l pagesize=auto

#let list(..xs) = {
  let xs = xs.pos()
  for (i, x) in xs.enumerate() {

    if i > 0 {
      if type(xs.at(i - 1)) == symbol and str(xs.at(i -1))==str("\u{2026}"){
        thin
      } else {
        set text(fill:red)
        $thin , thin$
      }
      
    }
    x
  }
}

$list(n_0, n_1, s) \
list(..., n_0, n_1, s) \
list(n_0, ..., n_m, s) \
list(n_0, n_1, ..., s) \
list(n_0, n_1, s, ...) \
list(n_0, ...,n_m, ..., s) \
list(..., n_0, n_1, s, ...) \
$