Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables of type 'string' rendered without spaces #56

Closed
michaellisitsa opened this issue Oct 20, 2020 · 4 comments
Closed

Variables of type 'string' rendered without spaces #56

michaellisitsa opened this issue Oct 20, 2020 · 4 comments

Comments

@michaellisitsa
Copy link
Contributor

Were a variable is declared with a 'string' and then rendered, the string is shown with all spaces removed.

How to reproduce

  • declare a variable
    name = "John Smith"
  • Render the variable
    Screen Shot 2020-10-20 at 9 21 33 pm

Expected behaviour
Show with a space.

Setup
Handcalcs 1.1.3
MacOS High Sierra
Jupyter Notebook

@connorferster
Copy link
Owner

Hi @michaellisitsa,

Dealing with multi-word text strings is a limited in handcalcs. Currently they are only handled within comments. I have run into this issue in my own scripts where I want to indicate a "flag" or something during the calculations. I have adapted the calculations to either use single words, descriptive subscripted variables, or booleans.

However, given your post to the Showcase (#50), I have a sense of what you may be trying to achieve. For creating a title block, I like to create a new Python module on my system to have a bunch of functions that I can pull into any new notebook, including this function:

from IPython.display import HTML

def title_block(
    name: str,
    proj: str,
    date: str,
    design: str,
    size: str = "1.5em"
):
    # This can be used to create a "title block" in your notebooks
    # before you start your calculations
    html_title = f"""
     <table style="width:100%; font-size:{size}; border:1px;">
          <tr>
            <td style="width:15%; text-align:right; font-weight:bold">Name: </td>
            <td style="width:35%; text_align:right">{name}</td>
            <td style="width:15%; text-align:right; font-weight:bold">Date: </td>
            <td style="width:35%; text_align:right">{date}</td>
          </tr>
          <tr>
            <td style="width:15%; text-align:right; font-weight:bold">Project: </td>
            <td style="width:35%; text_align:right">{proj}</td>
            <td style="width:15%; text-align:right; font-weight:bold">Design: </td>
            <td style="width:35%; text_align:right">{design}</td>
          </tr>
    </table> 
    """
    display(HTML(html_title))

Here is an example of the export to HTML and PDF printed in Chrome:

image

You can get even fancier and include your company logo in the title block, also!

@michaellisitsa
Copy link
Contributor Author

Thanks. It never crossed my mind to use HTML within a .py function. This would be useful when using PaperMill, where you may not want to manually edit the Markdown cells with separate headers.

@connorferster
Copy link
Owner

Oooh...that's a good call. I have not thought to parameterize my Markdown headers yet...Nice one!

@connorferster
Copy link
Owner

Going to close this issue for now. Still a problem but I do not anticipate fixing it unless it eventually becomes a major issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants