First time here? Check out the FAQ!

Ask Your Question
0

getting blank cells in html.table

asked 14 years ago

kcrisman gravatar image

I would like the following to give me a blank spot in a table in the notebook.

html.table([[1,None],[3,4]])

Unfortunately, it instead LaTeXs it to \mathrm{None}, which jsmath can't handle in any case. But I don't really want that behavior of latex() to change, but rather to figure out how to get the blank spot in the table without actually hacking the code of html.table (this is supposed to work on a server which is only updated once a semester).

Preview: (hide)

Comments

I built an EmptyCell class which changed _latex_ before realizing that even '' gives an empty cell.. is it too awkward to preprocess the table contents?

DSM gravatar imageDSM ( 14 years ago )

That's no problem at all. Are you saying that I could replace with an empty string? I didn't think about that.

kcrisman gravatar imagekcrisman ( 14 years ago )

Yes, this works. Can you make that an ANSWER so I can ACCEPT it? :-) Preferably with a nice example.

kcrisman gravatar imagekcrisman ( 14 years ago )

PS - I ran into trouble because I had tuples. So I had to do lists. But that was no problem either.

kcrisman gravatar imagekcrisman ( 14 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 14 years ago

DSM gravatar image

updated 14 years ago

html.table([[1, ''], [3,4]])

should do the trick, or, if like me you've gotten too object-oriented for your own good, you can do something like

class EmptyCell:
    def _latex_(self): return ''

Empty = EmptyCell()

html.table([[1, Empty], [3,4]])

which I'm only confessing to having written before even trying '' in the hopes that laughing at the above might help keep someone else from overthinking.

Preview: (hide)
link

Comments

I had to process my table ahead of time to do this, replacing None with the empty string, but that worked. Next up - figuring out how to process a list of lists more easily than with a double loop and then finding the right sublist index to replace...

kcrisman gravatar imagekcrisman ( 14 years ago )

b = [[i if i != None else '' for i in l] for l in a] does it without indices, although it does have a double loop.

DSM gravatar imageDSM ( 14 years ago )

Yeah, I'm always hesitant to do double list comprehensions, but this would work great. I don't count a list comprehension as anywhere nearly as inelegant as a for loop with colon and indentation.

kcrisman gravatar imagekcrisman ( 14 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 14 years ago

Seen: 731 times

Last updated: Feb 18 '11