# Freeform section of a notebook sent to a function for evaluation?

**URL:** <https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611>\
**Category:** Questions\
**Tags:** mathematica, interface-construction, computational-notebooks, ui-ux-and-ide\
**Created:** [March 28, 2020, 4:33am UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611 "2020-03-28T04:33:02Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jibanes](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jibanes](https://community.wolfram.com/u/jibanes)\
**Post date:** [March 28, 2020, 4:33am UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/1 "2020-03-28T04:33:02Z")

</div>

Hello, Is it possible to define a custom section of a notebook ( think for instance to type plain text ) and pass this section to a function as an argument (and escape the double quotes). For instance:

Cell #10: this is a section of this Mathematica notebook. these “contents” will be passed to the function below.

Cell #11: CustomFunction[“this is a section of this Mathematica notebook.\nthese "contents" will be passed to the function below.”]

Where of course modifying the contest of the freeform section would change the argument of CustomFunction[]. Or is there a construct like CustomFunction[%] which would indicate the contents of the cell above? Or perhaps CustomFunction[Cell[10]] or such?

Any ideas?

---

<div class="post-metadata">

**Author:** ![hansmilton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hansmilton/32/8656_2.png) [@hansmilton](https://community.wolfram.com/u/hansmilton)\
**Post date:** [March 28, 2020, 5:42pm UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/2 "2020-03-28T17:42:16Z")

</div>

Maybe:

## Arguments

```
args = {"3", "5"};

```

## Function

```
f[a_, b_] := a^b

```

## Evaluation

```
In[3]:= f[Sequence @@ ToExpression[args]]

Out[3]= 243

```

---

<div class="post-metadata">

**Author:** ![jibanes](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jibanes](https://community.wolfram.com/u/jibanes)\
**Post date:** [March 29, 2020, 12:41am UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/3 "2020-03-29T00:41:57Z")

</div>

Thanks, that helps already, now can “args = {“3”, “5”};” be something like:

```
{"3","5"};

```

in a single cell, probably with a plain-text stylesheet, like if a portion of the notebook was to be considered not-to-be evaluated, but to serve as string arguments to a function?

---

<div class="post-metadata">

**Author:** ![hansmilton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hansmilton/32/8656_2.png) [@hansmilton](https://community.wolfram.com/u/hansmilton)\
**Post date:** [March 29, 2020, 8:57am UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/4 "2020-03-29T08:57:25Z")

</div>

One possible approach is to use the option `CellTags` for the cell containing the string arguments. In this example the arguments are in a text cell with the tag Arguments. Default stylesheet.

![Taggedcell.png](https://global.discourse-cdn.com/wolfram/original/3X/2/a/2a3c98182d6431e95566ed4f570b491fc3760aa9.png)

```
In[1]:= f[a_, b_] := a^b

In[2]:= f[Sequence @@ ToExpression[NotebookLocate@"Arguments";First@NotebookRead@EvaluationNotebook[]]]
Out[2]= 243

```

---

<div class="post-metadata">

**Author:** ![jibanes](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jibanes](https://community.wolfram.com/u/jibanes)\
**Post date:** [March 29, 2020, 4:08pm UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/5 "2020-03-29T16:08:18Z")

</div>

![celltags.png](https://global.discourse-cdn.com/wolfram/original/3X/8/f/8f492003b0b6faf15c76c617b65a4223827e45e6.png)

---

<div class="post-metadata">

**Author:** ![hansmilton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hansmilton/32/8656_2.png) [@hansmilton](https://community.wolfram.com/u/hansmilton)\
**Post date:** [March 29, 2020, 5:08pm UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/6 "2020-03-29T17:08:16Z")

</div>

Your screenshot indicates that you have defined the “Arguments” cell to be an **Input** cell (or rather that it was made to be an **Input** cell when you copy/pasted it). But it needs to be defined as a **Text** cell. Since it is supposed to contain strings, not expressions that can be evaluated.

Cell type can be changed by selecting the cell and then rightclick:

 ![Textcell.png](https://global.discourse-cdn.com/wolfram/original/2X/2/2b4884e130fa4de5b273047cce7e6d831f19a1af.png)

[Freeform arguments 2.nb](https://community.wolfram.com/uploads/short-url/wFVIFEeSXar3BY3JzSV1KTtKi18.nb) (3.27 KB)

---

<div class="post-metadata">

**Author:** ![jibanes](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jibanes](https://community.wolfram.com/u/jibanes)\
**Post date:** [March 30, 2020, 3:53am UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/7 "2020-03-30T03:53:02Z")

</div>

Thank you, that’s a huge leap forward.  
How can I possibly make the following just print 1 2 3 (understand that I intend to replace the Print[] function with something else when this will be finalized).

Thank you.

 ![freeform.png](https://global.discourse-cdn.com/wolfram/original/2X/8/883f54479ea7dbcc82e8703a22716b7711f759c7.png)

Note: the cell with 1 2 3 is formatted as you mentioned above (read: style type text and cell argument type), that part seems to work I think.

---

<div class="post-metadata">

**Author:** ![hansmilton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hansmilton/32/8656_2.png) [@hansmilton](https://community.wolfram.com/u/hansmilton)\
**Post date:** [March 30, 2020, 5:02am UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/8 "2020-03-30T05:02:12Z")

</div>

Try this version:

```
f[NotebookLocate@"Arguments"; First@NotebookRead@EvaluationNotebook[]]

1 2 3

```

It passes the single argument as a string to the function.

---

<div class="post-metadata">

**Author:** ![jibanes](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jibanes](https://community.wolfram.com/u/jibanes)\
**Post date:** [March 30, 2020, 2:37pm UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/9 "2020-03-30T14:37:40Z")

</div>

This is perfect, thank you so much Hans!

Finally, can I have the “evaluating cell” automatically updated when the “text cell” is updated?

---

<div class="post-metadata">

**Author:** ![hansmilton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hansmilton/32/8656_2.png) [@hansmilton](https://community.wolfram.com/u/hansmilton)\
**Post date:** [March 31, 2020, 12:29pm UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/10 "2020-03-31T12:29:06Z")

</div>

Jerome, I cannot find a simple way to automatically trig evaluation when contents of the text cell are changed. Have experimented a bit with the cell option `CellEventActions` together with `Dynamic`. But no luck.

Maybe someone else has ideas.

---

<div class="post-metadata">

**Author:** ![jibanes](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jibanes](https://community.wolfram.com/u/jibanes)\
**Post date:** [March 31, 2020, 4:01pm UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/11 "2020-03-31T16:01:12Z")

</div>

Thanks Hans, it would have been nice; maybe with a button instead?

---

<div class="post-metadata">

**Author:** ![hansmilton](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hansmilton/32/8656_2.png) [@hansmilton](https://community.wolfram.com/u/hansmilton)\
**Post date:** [March 31, 2020, 5:11pm UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/12 "2020-03-31T17:11:04Z")

</div>

A `Button` has to be pressed to do its job. So the process is then no longer fully automatic. Two, manual, actions are required:

- Edit the string argument in the text cell (always required unless the argument is modified programmatically)
- Press the button to trig evaluation and get the result

But if this “dual action” is not a problem there are several ways to go ahead. With functions such as `Manipulate, InputField, DialogInput`. And others.

---

<div class="post-metadata">

**Author:** ![jibanes](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jibanes](https://community.wolfram.com/u/jibanes)\
**Post date:** [April 1, 2020, 12:04am UTC](https://community.wolfram.com/t/freeform-section-of-a-notebook-sent-to-a-function-for-evaluation/15611/13 "2020-04-01T00:04:30Z")

</div>

Thank you Hans, I’ll investigate; many thanks!
