Does \newcommand work?

solved

#1

I’m experimenting with Docx2LaTeX to see if it is feasible for use to do collaborative editing for a latex document that consists of mixed manually created and generated latex. The project is also stored in git so ideally changes in git would be reflected in the document.

Some of the generated latex uses custom commands which are currently defined is a cls file.

I was testing to see if \newcommand works. For a simple command that only returned text it worked if defined in the LaTeX block that uses it. It did not work by putting the \newcommand in the first latex block along with the documentclass.

\newcommand{\sayhello}[1]{Hello #1}
\sayhello{Mike}

Attempting to define a new command with use of ifthenelse fails. \usepackage{ifthen} is included alongside \documentclass in the first latex block.

\newcommand{\dayOfWeek}[1]
{
\ifthenelse{\equal{#1}{0}}{Sunday}{}
\ifthenelse{\equal{#1}{1}}{Monday}{}
\ifthenelse{\equal{#1}{2}}{Tuesday}{}
\ifthenelse{\equal{#1}{3}}{Wednesday}{}
\ifthenelse{\equal{#1}{4}}{Thursday}{}
\ifthenelse{\equal{#1}{5}}{Friday}{}
\ifthenelse{\equal{#1}{6}}{Saturday}{}
}
\dayOfWeek{0}
\dayOfWeek{4}


#2

Modifying one of the existing templates to add \usepackage{ifthenelse} fails to generate the PDF so I’m assuming the issue is with the usepackage. Is it generally the case that only packages already installed by Docx2LaTeX will be usable?


#3

We tested the scenarios you mentions both of them produce desired output.
Test Case 1:
Code:


Output:

Test Case 2:
Code:


Output:

Is there any other test case you were referring to?


#4

Well, unfortunately, it isn’t working for me…


#5

Use Convet To > LaTeX Source Code button and inspect the LaTeX source code to see what is going wrong.


#6

Unzipping the resulting file and running pdflatex directly results in the expected output… however, selecting the block and clicking the render button results in the image show previously.


#7

I’ve made the document accessible at the following link if it helps to diagnose:


#8

Ohh, so those screenshots were of rendered output!
Render feature is given only to get quick intuition of code block mostly for equations and tikz pictures .
However you should always prefer and trust output produced by, convert to PDF file button.