Can Chaste Q&A support code formatting?

+2 votes
asked Oct 12, 2017 by fcooper (390 points)
Would be good to include `code` between ticks, or

code blocks
etc.  Is this possible?

## Headings, etc would be nice, too

2 Answers

+1 vote
answered Oct 16, 2017 by MichaelClerx (700 points)
selected Oct 17, 2017 by MichaelClerx
Best answer


I've removed a bunch of languages so that the code autodetection will be much more likely to recognise C++ (as well as make, cmake, etc.)

Also tweaked the CSS to be less ugly.

The markdown engine used is the same as on stackoverflow, so you create code blocks by indenting everything.

class MyOdeUsingStateVariables : public AbstractOdeSystem
    MyOdeUsingStateVariables() : AbstractOdeSystem(1)
        mpSystemInfo = OdeSystemInformation<MyOdeUsingStateVariables>::Instance();

    void EvaluateYDerivatives(double time, const std::vector<double>& rY,
                              std::vector<double>& rDY)
        rDY[0] = rY[0]*rY[0] + time*time;
commented Oct 16, 2017 by MichaelClerx (700 points)

You may need to refresh after posting code to see the highlighting in effect...

0 votes
answered Oct 12, 2017 by fcooper (390 points)
edited Oct 12, 2017 by MichaelClerx



def f(x):
    # Do stuff
    print('Some Python code')
    x = 0
    for i in xrange(10):
        x += i
    return x

That was some code

commented Oct 12, 2017 by fcooper (390 points)
edited Oct 12, 2017 by MichaelClerx

Code block:

auto compare_short_axis = [&](const unsigned& a, const unsigned& b) ->bool
    const auto& to_a = p_mesh->GetVectorFromAtoB(centroid, elem_it->GetNode(a)->rGetLocation());
    const auto& to_b = p_mesh->GetVectorFromAtoB(centroid, elem_it->GetNode(b)->rGetLocation());
    return inner_prod(to_a, short_axis) < inner_prod(to_b, short_axis);

Welcome to Chaste Q&A, where you can ask questions and receive answers from other members of the community of Chaste developers and users.

See the Chaste wiki for installation instructions, guides and tutorials.